What's the difference between <a asp-page="linkhere"> and <a href="linkhere"> in ASP.NET Core?

This is a fundamental question:

What’s the real difference between <a asp-area="" asp-page="/linkhere">test</a> and classic <a href="/linkhere">test</a> in ASP.NET Core?

The end result appears to be the same always (it’s an href attribute always in the end)

Does it somehow protect against clickjacking or something similar behind the scenes??

In other words, does using asp-page bring any security advantages?

>Solution :

You can customise the routing for Razor Pages, so that your LinkHere Razor Page and the URL to the page may be different. In that case, the asp-page approach ensures that the URL will match the page, but the href approach would need to be updated accordingly.

For an example of how a Razor Page URL can be customised, see Configure a page route:

options.Conventions.AddPageRoute("/Contact", "TheContactPage/{text?}");

In this example, the page Contact has a URL of TheContactPage with an optional extra segment.

Leave a Reply