问题
Have a look at this code:
var callbackUrl = Url.Page("/Account/ConfirmEmail", null, new { userId = user.Id, code }, Request.Scheme);
The result is this:
http://localhost:5000/Account/Register?userId=614d16ae-4e95-4796-8d67-cb829e12585b&code=CfDJ8OeNFdnFCrtCsRU7ofatUuROudlTo%2BFQe84oAiL%2BPJSoYwGH9q1Xadg8XBbpOFg5DiRH1vDoGeQ8l3qIFHjB3NMM3ZDTlQexawj1b%2BJ7P6X3SHoBsYs7jLYwcfGQCbnk1SJA5koFkoDcWj04nsjzQlJMe8ttR0DFdi%2B6TTbWI8WkPBaS083O3aU%2BL2bbYGNwwikhrkbB0nHy4PRzK1LZuZo%3D&page=%2FAccount%2FConfirmEmail
Where does the Register come from? Why is it not Account/ConfirmEmail? I did create this in the Register method of Account controller, so I suppose register came from there, but why did it use that as opposed to what I passed in? I do see that it added it as a parameter at the very end, but why?
As far as I can tell, according to this, I did it right.
https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.urlhelperextensions.page?view=aspnetcore-2.1#Microsoft_AspNetCore_Mvc_UrlHelperExtensions_Page_Microsoft_AspNetCore_Mvc_IUrlHelper_System_String_System_String_System_Object_System_String_System_String_
I am using core 2.1 still.
EDIT: Their registration tutorial says the same thing as what I have above:
https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.1&tabs=visual-studio#scaffold-register-login-and-logout
If I use .Action
instead of .Page
I get my desired result, but I would like to know why .Page
acts differently.
回答1:
They are all used to generate url, however,Url.Action
is for MVC and Url.Page
is for Razor Pages.You use the code in Account controller which Url.Action
is needed.
Refer to Url Generation for controller/action and Url Generation for pages
In asp.net core 2.0,scaffold Identity uses the MVC while in asp.net core 2.1+, it uses Razor Pages.
来源:https://stackoverflow.com/questions/54620262/url-page-creates-wrong-url