如何在 ASP NET Core 2.2.0+ 中禁用注册表单?
只是为了获取和删除适当的模型,我不能,因为它不在项目中,根据文档,我知道这与“ConfigureApplicationPartManager”之类的东西有关
链接在这里
但我找不到合适的例子来禁用它
目标是禁用新用户的注册,只留下登录\密码表单
services.AddMvc()
.ConfigureApplicationPartManager(x =>
{
var thisAssembly = typeof(IdentityBuilderUIExtensions).Assembly;
var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(thisAssembly, throwOnError: true);
var relatedParts = relatedAssemblies.ToDictionary(
ra => ra,
CompiledRazorAssemblyApplicationPartFactory.GetDefaultApplicationParts);
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
Run Code Online (Sandbox Code Playgroud) 我想使用多个角色来访问应用程序中的视图,如果我使用一个角色,一切都会正常工作,但是当我使用多个角色时,视图不会提供访问权限
我的模型用户有这个:
export class User {
role: Role[]; // I change - role: Role[] for few roles
expiresIn: string;
aud: string;
iss: string;
token?: string;
}
export const enum Role {
Admin = 'admin',
User = 'user',
Engineer = 'engineer'
}
Run Code Online (Sandbox Code Playgroud)
我的后端给我的令牌和角色:
//....
role: (2) ["admin", "engineer"]
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ
//....
Run Code Online (Sandbox Code Playgroud)
如果我在登录方法中使用这个
tokenInfo['http://schemas.microsoft.com/ws/2008/06/identity/claims/role'][0] - first element in array
Run Code Online (Sandbox Code Playgroud)
我只有 1 个角色,并且代码工作正常,但我可以拥有属于不同角色的许多用户,并且如果至少有 1 个角色,我需要应用程序为他们提供访问权限
我处理令牌解码并获取授权服务中的角色
signin(username:string, password:string ) {
return this.http.post<User>(`${environment.apiUrl}${environment.apiVersion}Profile/Login`, {username, password})
.pipe(map(user => {
if (user && user.token) {
let …Run Code Online (Sandbox Code Playgroud)