Click here to Skip to main content
12,890,879 members (55,218 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 5 Jul 2011

Maintain Query String after Forms Authentication cookie expires

, 5 Jul 2011 CPOL
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);


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


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.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 5 Jul 2011
Article Copyright 2011 by Bahram Ettehadieh
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid