主视图中未设置对象引用错误 - MVC 客户端快速入门
Object ref not set Error from Home view - MVC client quickstart
我正在尝试完成 MVC 客户端快速入门,但 运行 在行中出现“对象引用未设置...”错误 - “@foreach (var prop in (await Context.AuthenticateAsync()).Properties.Items)" 从我的 Index.cshtml 里面,我按照快速入门文档修改了它。下面是完整的Index.cshtml。有人能告诉我我做错了什么吗?
@using Microsoft.AspNetCore.Authentication
<h2>Claims</h2>
<dl>
@foreach (var claim in User.Claims)
{
<dt>@claim.Type</dt>
<dd>@claim.Value</dd>
}
</dl>
<h2>Properties</h2>
<dl>
@foreach (var prop in (await Context.AuthenticateAsync()).Properties.Items)
{
<dt>@prop.Key</dt>
<dd>@prop.Value</dd>
}
</dl>
您缺少 .RequireAuthorization();
这部分代码:
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute()
.RequireAuthorization();
});
The RequireAuthorization method disables anonymous access for the entire application.
这里我有一个工作示例可以遵循:https://github.com/nahidf/IdentityServer4-adventures/tree/master/src/MvcClient
我正在尝试完成 MVC 客户端快速入门,但 运行 在行中出现“对象引用未设置...”错误 - “@foreach (var prop in (await Context.AuthenticateAsync()).Properties.Items)" 从我的 Index.cshtml 里面,我按照快速入门文档修改了它。下面是完整的Index.cshtml。有人能告诉我我做错了什么吗?
@using Microsoft.AspNetCore.Authentication
<h2>Claims</h2>
<dl>
@foreach (var claim in User.Claims)
{
<dt>@claim.Type</dt>
<dd>@claim.Value</dd>
}
</dl>
<h2>Properties</h2>
<dl>
@foreach (var prop in (await Context.AuthenticateAsync()).Properties.Items)
{
<dt>@prop.Key</dt>
<dd>@prop.Value</dd>
}
</dl>
您缺少 .RequireAuthorization();
这部分代码:
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute()
.RequireAuthorization();
});
The RequireAuthorization method disables anonymous access for the entire application.
这里我有一个工作示例可以遵循:https://github.com/nahidf/IdentityServer4-adventures/tree/master/src/MvcClient