登录页面中的会话检查 [英] Session check in login page

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

问题描述



注销按钮使用下面的代码清除会话,然后重定向登录

页面。



Hi,
the logout button clear the session using the code below and then redirect to login
page.

FormsAuthentication.SignOut();
            Session.Clear();
            Session.Abandon();





然后,每个页面调用一个函数ValidateSession()在类checkLogIn中作为

页面加载事件中的CheckLogIn.ValidateSession()。



函数ValidateSession()如下,





Then, each page call a function ValidateSession() in a class checkLogIn as
CheckLogIn.ValidateSession() in page load event.

the function ValidateSession() as below,

public static void ValidateSession()
        {
            try
            {
                string sUserId = System.Web.HttpContext.Current.Session["UserId"].ToString();
            }
            catch (Exception oException)
            {
                System.Web.HttpContext.Current.Session["UserId"] = "sessionOut";
                System.Web.HttpContext.Current.Response.Redirect("~/Account/Login.aspx");

            }
            
        }







然后,检查会话,登录页面的页面加载事件中的会话[LoginId]。

如下






Then, check the session, Session["LoginId"] in page load event of login page.
as below

if (Session["UserId"] != null)
           {
               ScriptManager.RegisterStartupScript(this, this.GetType(), "alertscript", "find()", true);
           }







但会话[UserId] == null.why?



谢谢..




But the Session["UserId"]==null.why?

Thanks..

推荐答案

好像你没有分配价值到 Session [User_ID] ..所以试试

Its seems like you''re not assigning value to Session["User_ID"].. So try
Session["User_ID"] = UserNameTxt.Text ;



希望它能解决您的问题.. :)


Hope it will solve your problem.. :)


这篇关于登录页面中的会话检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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