Click here to Skip to main content
Click here to Skip to main content

Tagged as

Maintain Query String after Forms Authentication cookie expires

, 5 Jul 2011
Rate this:
Please Sign up or sign in to vote.
Maintain Query String after forms authentication cookie expires and the user is redirected to the login page.

When forms authentication cookie expires, the user will be redirected to the login page (which is set in the config file). After login, you can redirect the user to the page that he/she was in before expiration according to the ReturnUrl parameter provided by forms authentication. Using the code block below, you can also maintain the Query String of the page before expiration:

string querystring = "";
 
foreach (string key in Request.Params.AllKeys)
{
    string value = Request.QueryString[key];
    if (!string.IsNullOrEmpty(value))
        querystring += "&" + key + "=" + value;
}
if (querystring.Length > 0)
    querystring = Server.UrlEncode(querystring.Remove(0, 1));
 
Response.Redirect(FormsAuthentication.LoginUrl + "?ReturnUrl=" + 
         System.Web.HttpContext.Current.Request.Url.AbsolutePath + "?" + querystring);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Bahram Ettehadieh
Web Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I hold a BS degree in software engineering and am a Microsoft Certified Solution Developer(MCSD).
I have more than 8 years of experience in .NET developement, mostly web develop using C# and ASP.NET.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 5 Jul 2011
Article Copyright 2011 by Bahram Ettehadieh
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid