Why aren't ASP.NET MVC tag helpers creating the correct link?

Clash Royale CLAN TAG#URR8PPPWhy aren't ASP.NET MVC tag helpers creating the correct link?
I have an asp.net core MVC project with scaffolded Identity, and the tag helpers in the _LoginPartial view are acting wonky. In the Razor view, the link looks like this and don't navigate to any page or view.
<a class="nav-link" asp-area="Identity" asp-page="/Account/Manage/Index">Manage Account</a>
but for some reason it's being rendered like this (taken from the dev console in chrome):
href="/?area=Identity&page=%2FAccount%2FManage%2FIndex"
I don't know why this is happening and I can't figure out how to get it to render properly and allow navigation to the correct page.
asp-controller=".."
asp-action="..."
asp-page="/Account/Manage/Index" write like this=> asp-page="~/Account/Manage/Index"
– Tazbir Bhuiyan
2 days ago
@TazbirBhuiyan that throws an InvalidOperationException
– db2
2 days ago
default routing controller template: "{controller=Home}/{action=Index}/{id}/{closeOnSubmit?}" How is your controller routing template?
– Tazbir Bhuiyan
2 days ago
I had to delete my answer. This is a mess, including the docs and scouring the github issues. I found this hiding, it may be of some help: docs.microsoft.com/en-us/aspnet/core/security/authentication/…
– Adam Vincent
yesterday
2 Answers
2
I actually found out the issue. In the IdentityHostingStartup class in the Configure method of the Identity area, I had changed services.AddDefaultIdentity<IdentityUser> to services.AddIdentity(IdentityUser, IdentityRole> It doesn't make sense to me why that changes how the URLs are generated, but as soon as I changed it back to services.AddDefaultIdentity<IdentityUser> things returned to normal.
Identity
services.AddDefaultIdentity<IdentityUser>
services.AddIdentity(IdentityUser, IdentityRole>
services.AddDefaultIdentity<IdentityUser>
You can try following
<a asp-area="Account"
asp-controller="Manage"
asp-action="Index">About Blog</a>
It will create following html
<a href="/Account/Manage/Index">About Blog</a>
If you have custom Route mapping like below
[Route("/Speaker/Evaluations", Name = "speakerevals")]
public IActionResult Evaluations() => View();
Then try
<a asp-route="speakerevals">Speaker Evaluations</a>
It will create html like below
<a href="/Speaker/Evaluations">Speaker Evaluations</a>
For more information click here
You absolutely can mix
<asp-area=".."> and <asp-page="..">, especially since that's how it's wired up in the template generated from the dotnet new mvc --auth Individual command– db2
yesterday
<asp-area="..">
<asp-page="..">
dotnet new mvc --auth Individual
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You should be using
asp-controller=".."andasp-action="..."– Stephen Muecke
2 days ago