如何处理登录页面请建议 [英] how to handle seesion into login page please suggest

查看:156
本文介绍了如何处理登录页面请建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




i有一个查询关于



i在asp.net(C#)中创建了一个应用程序,其中有两个webforms登录.aspx和home page.aspx和我运行此应用程序到浏览器。当我成功登录然后它将我将直接到主页并显示欢迎用户名(通过使用会话)。每当我复制网址并将其粘贴到该浏览器的另一个标签页时,都会显示相同的主页,但是我的requirmnet是应该重定向登录页面而不是Home pAge。



所以请在这种情况下建议如何处理会话!!!!

Hi
i have one query about

i created one application in asp.net(C#)with two webforms login.aspx and home page.aspx and i run this application into browser.When i successfully login then it i will direct to Home page and showing welcome Username(By using Session). whenever i copy the url and paste it into another tab of that browser the same homepage is shown but my requirmnet is it should be redirected login page instead of Home pAge.

So please suggest How to handle the session in this case !!!!

推荐答案

它不会那样工作 - 登录信息通常保存在Cookies中这些存储在客户端PC上 - 所以如果他打开一个新窗口而没有注销或关闭他的浏览器,那么他仍然会登录。



你要么必须存储Sesssion中的登录并从那里检查(浏览器选项卡是唯一的)或者在您进行登录检查时添加并检查会话ID。这些Boith可能意味着实现一个自定义成员资格提供者 - 如果(我假设)你已经使用了会员资格,这并不是太难。 MSDN可以提供帮助: http://msdn.microsoft.com/en-us /library/f1kyba5e(v=vs.100).aspx [ ^ ]
It doesn''t work that way - the login info is normally saved in the Cookies which are stored on the client PC - so if he opens a new window without logging out or closing his browser then he remains logged in.

You would either have to store the login in the Sesssion and check it from there (which is unique to the browser tab) or add and check the session ID when you do teh login check. Boith of these will probably mean implementing a custom Membership Provider - which isn''t too difficult if (as I assume) you are using Membership already. MSDN can help: http://msdn.microsoft.com/en-us/library/f1kyba5e(v=vs.100).aspx[^]


希望这会对你有所帮助..



Hope this will help you..

protected void Page_Load(object sender, EventArgs e)
 {
     if (!this.IsPostBack)
     {
         if (Request.UrlReferrer == null)
         {
             Session.Abandon();
             Response.Redirect("login.aspx");
         }
     }
 }





如果您复制粘贴到另一个网址选项卡表示没有上一页。因此,如果没有以前的页面引用,此代码将重定向到登录页面。

..



If you copy paste the url in another tab means there is no previous page. So if no previous page reference this code will redirect to login page.
..


这可以通过会话来完成

如果用户的身份验证在登录页面中是正确的,那么您可以在主页上匹配会话。

i将为您提供示例,如果在登录页面上正确登录然后通过会话



this can be done by the session
if the user''s authentication is right in login page then you can match session at home page.
i will give you example if right login at login page then pass session

 Session["user"] = txtuser.Text;
Response.Redirect("adminhome.aspx");





并在主页上检查用户身份验证





and in home page check the user authentication

Labeluser.Text = Session["user"].ToString();
                str = "select * from login where username='" + Labeluser.Text + "'";
                cmd = new OleDbCommand(str, Classcon.con);
                dtp = new OleDbDataAdapter(cmd);
                ds = new DataSet();
                dtp.Fill(ds);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    Response.Redirect("loginpage.aspx");
                }
                else
                {
                    // Response.Redirect("adminhome.aspx");
                }


这篇关于如何处理登录页面请建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆