I am using the new Identity UI package available since ASP.NET Core 2.1 was released. Using a newly generated MVC project, here are some page URLs that are available:
/Home/About
/Home/Contact
/Identity/Account/Login
/Identity/Account/Register
How can I configure routing to remove the /Identity/
part from the URLs?
It looks like this is not yet possible. Looking at the source code, it's clear that the Area name is hardcoded in IdentityDefaultUIConfigureOptions<TUser>
:
private const string IdentityUIDefaultAreaName = "Identity";
This is used in a handful of places, including when configuring Razor Pages. e.g.:
options.Conventions.AuthorizeAreaFolder(IdentityUIDefaultAreaName, "/Account/Manage");
And also when configuring the Cookies authentication. e.g.:
options.LoginPath = $"/{IdentityUIDefaultAreaName}/Account/Login";
It's worth noting that IdentityDefaultUIConfigureOptions<TUser>
itself is protected, so the ability to override the options does not appear to exist.
I've opened a Github issue to see if we can get feedback from those involved in the project itself.
2018-06-12 Update
Javier Calvarro Nelson from the ASP.NET Core Identity team provided some valuable feedback in the Github issue I raised, which can be summarised as follows:
The main reason for the Identity UI to be in an area is to minimize the impact on your app and to provide a clean separation between your app code and the Identity code.
Javier recommends one of the following options when wanting to customise the URLs:
Although unsupported and not recommended, Javier also points out that it is possible to use a custom IPageApplicationModelConvention
to override the URLs. However, in case you missed it, this is unsupported and not recommended.
2018-06-27 Update
The official documentation has now been updated to better explain said URL changes.
The easiest thing to do, is to drag the Pages folder out of the Areas/Identity to the main project Remember that the @page directive (in the .cshtml) causes the views to be accessible directly for anything under "Pages" (the page is turned into an action) You could also rename the Account folder to some other name if you wanted to change the default /Account/Login etc pages
the @page directive can also be used to specify a custom path, such as: @page "/Login"
to have access to the login page directly by navigating to /Login
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With