Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReturnUrl is null in ASP.NET Core login

I have ASP.NET Core application with individual accounts; very similar to what gets generated by VS2017. For testing purposes I put [Authorize] attribute on About() action in Home controller. I am redirected to Login page as expected, and I see that URL is http://localhost:5000/Account/Login?ReturnUrl=%2FHome%2FAbout - also as expected. However, in the POST Login method ReturnUrl is null. I have Login method in Account Controller:

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginInputModel model) {
...
}

I also tried ReturnUrl as parameter explicitly, with or without [FromQuery]. In all permutations it is null.

like image 677
Felix Avatar asked Mar 08 '23 21:03

Felix


1 Answers

You should be sure that you are using

Html.BeginForm("Login", "Account", new {ReturnUrl = Request.QueryString["ReturnUrl"] })


[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginInputModel model, string ReturnUrl) {
...
}
like image 118
hasan Avatar answered Mar 11 '23 11:03

hasan