when user tries to access a restricted page with a querystring parameter

eg myaccount.aspx?sid=3&page=2

and is not authenticated, user will be redirected to login.aspx page.

the problem is that the querystirng (sid=3&page=2) will be lost .

the returnURL will be like "login.aspx?returnurl=myaccount.aspx". is there any solution for that? thanks.

Recommended Answers

All 4 Replies

Use session object instead of query string.

when u tried to open your "myaccount.aspx?sid=3&page=2" page it will redirect to your login page if user could not logged in. On login page read query string and send accordingly as per query string. Like if u are come from myaccount.aspx?sid=3&page=2 page then set myaccount.aspx?sid=3&page=2&page=myaccount then read this query string value on login page. AS per the page you can set redirection using response.redirect("myaccount.aspx?sid=3&page=2").

Thanx adatpost for ur suggestion.
if i store those query string in session, but it doesnt make any sense to store it in session although we have return url, just it cut downs our parameter list to single parameter.
I have to find solution within return URL only.
Can u help me??

I don't think that the value will be lost if you have a Forms authentication mode.

You need to write following code in login page to get named collection of query string key-value.

string query=System.Web.HttpUtility.UrlDecode( Request["ReturnURL"]);
        System.Collections.Specialized.NameValueCollection coll= System.Web.HttpUtility.ParseQueryString(query.Split('?')[1]);
        

        Label1.Text = "";
        foreach (string   t in coll.AllKeys )
        {
           Label1.Text += "<br/>" + t  + " : " + coll[t] ;
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.