I'm working on an mvc .net application and I'm using forms authentication. I want to redirect user to the page he requested after he gets authenticated. Any help would be appreciated.
相关问题
- MVC-Routing,Why i can not ignore defaults,The matc
- java client program to send digest authentication
- Entity Framework throws exception - Network Relate
- parameters in routing do not work MVC 3
- PHP persistent login - Do i reissue a cookie after
相关文章
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- How to get a list of connected clients on SignalR
- How do you redirect to the calling page in ASP.NET
- Change color of bars depending on value in Highcha
- The program '[4432] iisexpress.exe' has ex
- ASP.Net MVC 4 Bundles
- How to get server path of physical path ?
If you create an ASP.NET MVC 3 or 4 Internet Application project, it'll have a complete example of how to use return url's when authenticating.
When you add the AuthorizeAttribute to a controller to force authentication, it'll redirect the user to your Login method, and automatically append the returnUrl parameter. From there, you need to keep track of it as you show your login form:
and then add it to your login form's route collection:
Once the user submits the login, assuming they authenticate properly, you'll just redirect to returnUrl:
The hardest part is keeping track of the ReturnUrl through the GET/POST sequence.
If you want to see how the AuthorizeAttribute works, this StackOverflow post shows setting returnUrl with the original request.
You also need to make sure you validate returnUrl really is a local url, or you become vulnerable to open redirection attacks. RedirectToLocal() is a helper method from the MVC 4 Internet Application template that does this validation: