更改 ASP.NET Core Identity UI 中的路由? [英] Change routing in ASP.NET Core Identity UI?

查看:29
本文介绍了更改 ASP.NET Core Identity UI 中的路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自 ASP 以来可用的新 Identity 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?

推荐答案

看起来这还不可能.查看源码,很明显Area名称是IdentityDefaultUIConfigureOptions 中硬编码:

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 本身是受保护的,因此似乎不存在覆盖选项的能力.

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:

身份 UI 位于一个区域的主要原因是为了尽量减少对您的应用的影响,并在您的应用代码和身份代码之间提供清晰的分离.

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.

当想要自定义 URL 时,Javier 推荐以下选项之一:

Javier recommends one of the following options when wanting to customise the URLs:

  • 使用默认 UI 的脚手架元素并自行进行所有必要的自定义.
  • 使用重定向规则将旧路由指向新路由.
  • 完全不要使用默认用户界面.

尽管不受支持且不推荐,Javier 还指出可能使用自定义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 更新

官方文档现已更新,以更好地解释上述网址更改.

The official documentation has now been updated to better explain said URL changes.

这篇关于更改 ASP.NET Core Identity UI 中的路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆