When navigating to http://localhost:62030/Home/About and the Home controller includes the [Authorize] attribute the app correctly returns a 302 redirect to http://localhost:62030/Account/Login but w/o a ReturnUrl instead of http://localhost:62030/Account/Login?ReturnUrl=%2FHome%2FAbout This seems to have started recently however I'm not aware of the cause. When creating a new mvc project the redirect properly returns a redirect along with the ReturnUrl. Where has the ReturnUrl gone?
3 Answers
Answers 1
You should be sure that you are using ReturnUrl in controller and view
Html.BeginForm("YourLogin", "Account", new {ReturnUrl = Request.QueryString["ReturnUrl"] }) [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult YourLogin(LoginInputModel model, string ReturnUrl) { ... }
Answers 2
Set the form authentication since ASP.NET MVC template is using Forms authentication.
<authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="2880" /> </authentication>
You can also refer the link:Return URL
Answers 3
Due to the way the Authorization Filters work ( [Authorize] Works as a Filter )
you would never receive the request in HomeController.
To be using [Authorize] you're probably using Identity as Authentication/Authorization Middleware.
You should define the LoginPath correctly in your web.config.
0 comments:
Post a Comment