Asp.net 还记得会话超时后的页面吗

Asp.net 还记得会话超时后的页面吗,asp.net,session,c#-4.0,session-timeout,request.querystring,Asp.net,Session,C# 4.0,Session Timeout,Request.querystring,在我的网站中,我想将用户重定向到会话超时前他/她所在的页面 我尝试通过querystring发送url,但没有成功,因为url还包含“&” 我的url是:Default.aspx?FileID=23&TabID=3 查询字符串只有Default.aspx?FileID=23,并且省略了TabID。有什么办法我也能得到它吗?如果不使用querystring,还有其他方法吗?如果使用FormsAuthentication: 登录: FormsAuthentication.RedirectFromLo

在我的网站中,我想将用户重定向到会话超时前他/她所在的页面

我尝试通过querystring发送url,但没有成功,因为url还包含“&”

我的url是:
Default.aspx?FileID=23&TabID=3


查询字符串只有
Default.aspx?FileID=23
,并且省略了TabID。有什么办法我也能得到它吗?如果不使用querystring,还有其他方法吗?

如果使用FormsAuthentication:

登录:

FormsAuthentication.RedirectFromLoginPage() 

注销:

FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();

如果您正在使用FormsAuthentication:

登录:

FormsAuthentication.RedirectFromLoginPage() 

注销:

FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();

当会话超时时,如果使用forms auth只是FormsAuthentication.RedirectToLoginPage(),请尝试此操作;已经足够了,但如果您想重定向到登录以外的其他页面,请使用下面的自定义行。并使用Server.UrlEncode允许&in查询字符串

     public static  void DisposeAndLogout()
            {

                HttpContext context = HttpContext.Current;
                try
                {
                    FormsAuthentication.SignOut();
                    FormsAuthentication.Initialize();
                    Roles.DeleteCookie();
                    context.Session.Clear();
                }
                catch (Exception ex)
                {
                    ErrorHandler.HandleException(ex);
                }
                finally
                {
                    FormsAuthentication.RedirectToLoginPage();
//or can send to some other page
                    string OriginalUrl = context.Request.RawUrl;
                    string LoginPageUrl = @"~\Login.aspx";
                    context.Response.Redirect(String.Format("{0}?ReturnUrl={1}", LoginPageUrl, context.Server.UrlEncode(OriginalUrl)));
                }
            }

会话超时时,如果使用forms auth,请尝试此操作,但仅限于FormsAuthentication.RedirectToLoginPage();已经足够了,但如果您想重定向到登录以外的其他页面,请使用下面的自定义行。并使用Server.UrlEncode允许&in查询字符串

     public static  void DisposeAndLogout()
            {

                HttpContext context = HttpContext.Current;
                try
                {
                    FormsAuthentication.SignOut();
                    FormsAuthentication.Initialize();
                    Roles.DeleteCookie();
                    context.Session.Clear();
                }
                catch (Exception ex)
                {
                    ErrorHandler.HandleException(ex);
                }
                finally
                {
                    FormsAuthentication.RedirectToLoginPage();
//or can send to some other page
                    string OriginalUrl = context.Request.RawUrl;
                    string LoginPageUrl = @"~\Login.aspx";
                    context.Response.Redirect(String.Format("{0}?ReturnUrl={1}", LoginPageUrl, context.Server.UrlEncode(OriginalUrl)));
                }
            }

您在使用表单身份验证吗?您在使用表单身份验证吗?非常感谢。这就是我要找的。非常感谢。这就是我要找的。