The sequence of actions that I am trying to accomplish is below.
Context: user can add products to its own account.
Thanks.
When you redirect to the login page, add the original URL in the querystring.
After a successful login, send a to the URL from the querystring.
Assuming you are using FormsAuthentication, if you are not, or don't know what to use, check it out here: http://msdn.microsoft.com/en-us/library/xdt4thhy.aspx
OK, so when your user tries to access a page that is protected (ie they have to be logged it), ASP.NET's forms authentication will send them to the login page, which is best set up in the web config:
<authentication mode="Forms">
<forms loginUrl="~/Public/Login.aspx" defaultUrl="~/Public/Default.aspx"/>
</authentication>
It will also attach a ReturnUrl query string parameter to the that, so the login page knows where they came from: http://www.example.com/Public/Login.aspx ?ReturnUrl=%2fprivate%2forderproduct.aspx
Then, in your login page, assuming that they have successfully authenticated, you set the authentication cookie and redirect them back from whence they came:
FormsAuthentication.SetAuthCookie(someUserIdentifier,isRememberMeSet);
FormsAuthentication.RedirectFromLoginPage(someUserIdentifier, isRememberMeSet);
Of course, if you don't want to use FormsAuthentication, you can still use the concept of the return URL. Forms authentication just gives you a lot of that for free.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.