这个问题可以通过在Identity视图中添加以下行来解决。首先,您需要检查您的Views中是否有名为“_ViewStart.cshtml”的文件,并且它包含以下内容:
@{
Layout = "_Layout";
}
然后,在Identity视图中添加以下行:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
在这个示例中,我们使用了共享布局(_Layout.cshtml),但是如果您有另一个布局文件,则需要相应地更改文件路径。
如果您仍然遇到问题,请确保您的应用程序已经正确配置了中间件和服务:
在Startup.cs文件的Configure方法中添加以下代码:
app.UseMvcWithDefaultRoute();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
在Startup.cs文件的ConfigureServices方法中添加以下代码:
services.AddMvc();
services.AddAuthorization();
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
//your configuration options here
});