Reputation: 29737
Some of my pages are restricted only to loggedIn users. When the one tries to enter that page I redirect him to the login page. Then after successful login I would like to redirect him to the previously desired page.
Where can I keep that url ?
I cant use session mechanism
Thank You very much for help
Upvotes: 1
Views: 104
Reputation: 20617
Just use forms auth and use the built in ReturnUrl
:
Explained: Forms Authentication in ASP.NET 2.0
Cookieless Forms Authentication
ASP.NET 2.0 supports cookieless forms authentication. This feature is controlled by the cookieless attribute of the forms element. This attribute can be set to one of the following four values:
UseCookies. This value forces the FormsAuthenticationModule class
to use cookies for transmitting the authentication ticket. UseUri. This value directs the FormsAuthenticationModule class to rewrite the URL for transmitting the authentication ticket. UseDeviceProfile. This value directs the FormsAuthenticationModule class to look at the browser capabilities. If the browser supports cookies, then cookies are used; otherwise, the URL is rewritten. AutoDetect. This value directs the FormsAuthenticationModule class to detect whether the browser supports cookies through a dynamic detection mechanism. If the detection logic indicates that cookies are not supported, then the URL is rewritten.
If your application is configured to use cookieless forms authentication and the FormsAuthentication.RedirectFromLoginPage method is being used, then the FormsAuthenticationModule class automatically sets the forms authentication ticket in the URL. The following code example shows what a typical URL looks like after it has been rewritten:
Upvotes: 0
Reputation: 218837
I would argue that the "best" way is to not remember that URL at all, but instead to pass it as a query string value to the login page. It's a more stateless approach.
When you redirect the user to the login page, you can URL encode the path to the redirecting page and add it to the query string in the redirect. Then, in your login page, check for that value. If the value exists (and passes any validation you wish to add, such as ensuring that it's a relative path to your own site and is a valid page, etc.), redirect the user to that page. If it doesn't exist, redirect to a default page.
Upvotes: 1
Reputation: 21881
Put it in the querystring e.g.
http://www.mysite.com/login.aspx?RedirectUrl=SomeRestrictedPage.aspx
Upvotes: 1
Reputation: 11041
You can put it in the QueryString like Asp.Net Membership does.
http://www.example.com/Login?returnUrl=/home/
Upvotes: 5