更改ASP.NET Core Identity UI中的路由?

编程入门 行业动态 更新时间:2024-10-11 09:27:39
本文介绍了更改ASP.NET Core Identity UI中的路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用自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中的路由?

本文发布于:2023-11-17 09:04:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609558.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   NET   ASP   Core   UI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!