在我的网站中,我想将用户重定向到会话超时之前他/她所在的同一页面。
我通过查询字符串发送 url 来尝试它,但它没有成功,因为 url 还包含“&”。
我的网址是:Default.aspx?FileID=23&TabID=3
。
查询字符串只有Default.aspx?FileID=23
并且 TabID 被省略。有什么办法我也可以得到它吗?如果不使用查询字符串,还有其他方法吗?
在我的网站中,我想将用户重定向到会话超时之前他/她所在的同一页面。
我通过查询字符串发送 url 来尝试它,但它没有成功,因为 url 还包含“&”。
我的网址是:Default.aspx?FileID=23&TabID=3
。
查询字符串只有Default.aspx?FileID=23
并且 TabID 被省略。有什么办法我也可以得到它吗?如果不使用查询字符串,还有其他方法吗?
当会话超时尝试这个,如果使用表单身份验证只是 FormsAuthentication.RedirectToLoginPage(); 就足够了,但是如果您想重定向到登录以外的其他页面,请使用下面的自定义行。并使用 Server.UrlEncode 在查询字符串中允许 &
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)));
}
}
如果您使用 FormsAuthentication:
登录:
FormsAuthentication.RedirectFromLoginPage()
http://msdn.microsoft.com/en-us/library/ka5ffkce.aspx
登出:
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.signout.aspx