上一页 下一页 ASP.NET 应用程序和会话超时重定向
我有一个应用程序,我试图在会话超时时进行重定向,因此在我的母版页中,我正在检查重定向的会话变量是否为空,但问题是我有来自母版页的其他页面(派生)以及派生的 Page_Load我还引用了一些会话变量,并且我观察到派生页面(内容)的 PAGE_LOAD 事件首先触发,母版页 PAGE_LOAD 稍后触发,因此错误弹出“对象引用未设置”。
顺便说一句,我正在 LOGIN_BUTTON_PRESSED EVENT 上编写以下代码。
FormsAuthenticationTicket ticket - new FormsAuthenticationTicket(1, userName, DateTime.Now, DataTime.Now.AddMinutes(20), true, myRoles, FormsAuthentication.FormsCookiePath);
Session["uid"] = userName.Text;
Session["ufullname"] = ufname;
string hashCookies = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);
Response.Cookies.Add(cookie);
Response.Redirect("~/Main.aspx");
请通过示例提出解决此问题的解决方案。
I have a application where I am trying to redirect on session time out so therefore in my master page I am checking if session variable is null for the redirection but the problem is that I have other pages(derived) from masterpage and on Page_Load of derived pages i am referencing some session variables there also and I've observed that PAGE_LOAD event of derived pages(content) fires first and master page PAGE_LOAD fires later so the error is popping "Object reference not set".
By the way I am writing following code on LOGIN_BUTTON_PRESSED EVENT.
FormsAuthenticationTicket ticket - new FormsAuthenticationTicket(1, userName, DateTime.Now, DataTime.Now.AddMinutes(20), true, myRoles, FormsAuthentication.FormsCookiePath);
Session["uid"] = userName.Text;
Session["ufullname"] = ufname;
string hashCookies = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);
Response.Cookies.Add(cookie);
Response.Redirect("~/Main.aspx");
Please suggest a solution to overcome this problem with example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种选择是将母版页 Page_Load 事件中的代码移至 Page_Init 事件:
请参阅 ASP.NET 页面生命周期概述
One option is to move the code in your master page Page_Load event, to the Page_Init event:
See ASP.NET Page Life Cycle Overview