我正在使用自ASP以来可用的新身份UI 程序包. NET Core 2.1已发布.使用新生成的MVC项目,以下是一些可用的页面URL:
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如何配置路由以从URL中删除/Identity/部分?
How can I configure routing to remove the /Identity/ part from the URLs?
推荐答案看来这还不可能.查看源代码,很明显,区域名称为在IdentityDefaultUIConfigureOptions<TUser> 中进行了硬编码:
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";在很多地方都可以使用它,包括配置Razor页面.例如:
This is used in a handful of places, including when configuring Razor Pages. e.g.:
options.Conventions.AuthorizeAreaFolder(IdentityUIDefaultAreaName, "/Account/Manage");以及配置Cookies身份验证.例如:
options.LoginPath = $"/{IdentityUIDefaultAreaName}/Account/Login";值得注意的是,IdentityDefaultUIConfigureOptions<TUser>本身受到保护,因此似乎不存在覆盖选项的功能.
It's worth noting that IdentityDefaultUIConfigureOptions<TUser> itself is protected, so the ability to override the options does not appear to exist.
我已经打开了 Github问题,看看我们是否可以从这些问题中获得反馈参与项目本身.
I've opened a Github issue to see if we can get feedback from those involved in the project itself.
2018-06-12更新
ASP.NET Core Identity团队的Javier Calvarro Nelson在 Github问题我提出来,可以总结如下:
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:
Identity UI位于某个区域的主要原因是为了最大程度地减少对应用程序的影响,并在应用程序代码和Identity代码之间实现清晰的分隔.
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建议自定义URL时使用以下选项之一:
Javier recommends one of the following options when wanting to customise the URLs:
- 使用默认UI的scaffolding元素,然后自行进行所有必要的自定义.
- 使用重定向规则将旧路由指向新路由.
- 完全不使用默认用户界面.
尽管不受支持且不推荐,但哈维尔还指出,使用自定义 IPageApplicationModelConvention 覆盖URL.但是,以防万一您错过了它,这是不受支持,不建议.
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更新
官方文档现在已更新,可以更好地解释所说的URL更改.
The official documentation has now been updated to better explain said URL changes.
更多推荐
更改ASP.NET Core Identity UI中的路由?
发布评论