Reputation: 1161
In my website I want to redirect the user to the same page on which he/she was before the session timeout.
I tried it by sending the url through querystring, but it didn't work out as the url also contained "&".
My url was: Default.aspx?FileID=23&TabID=3
.
The querystring had only Default.aspx?FileID=23
and TabID was omitted. Is there any way I can also get it? If not with querystring, is there any other method?
Upvotes: 0
Views: 1877
Reputation: 4585
When Session timeout try this, if using forms auth just FormsAuthentication.RedirectToLoginPage(); is enough but if you want to redirect to some other page than login use custom line below. and use Server.UrlEncode to allow & in querystring
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)));
}
}
Upvotes: 2
Reputation: 7525
If you are using FormsAuthentication:
Login:
FormsAuthentication.RedirectFromLoginPage()
http://msdn.microsoft.com/en-us/library/ka5ffkce.aspx
Logout:
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.signout.aspx
Upvotes: 1