InvalidOperationException:无法找到布局视图“/views/shared/_Layout.cshtml”

问题描述 投票:0回答:1

我将我的项目从 .net core 3.0 重构为 .net6,当我转换它时,该项目无法在 HTTPS 上运行,而在 HTTP 上运行,然后我创建了一个新项目并在运行我的应用程序时获取了所有文件,我遇到了这些问题,我无法确定什么问题 这是第一期

InvalidOperationException:无法找到布局视图“/views/shared/_Layout.cshtml”。

第二期

InvalidOperationException:默认的 Identity UI 布局需要通常位于“/Pages/_LoginPartial”或“/Views/Shared/_LoginPartial”的部分视图“_LoginPartial”才能工作。根据您的配置,我们在以下位置查看了它:

/Areas/Identity/Pages/Account/_LoginPartial.cshtml
    /Areas/Identity/Pages/_LoginPartial.cshtml
    /Areas/Identity/Pages/Shared/_LoginPartial.cshtml
    /Areas/Identity/Views/Shared/_LoginPartial.cshtml
    /Pages/Shared/_LoginPartial.cshtml
    /Views/Shared/_LoginPartial.cshtml.

我的项目配置

    var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var services = builder.Services;
services.AddDbContext<GasdwahedDbContext>(options =>
{
    options.UseSqlServer(
        builder.Configuration.GetConnectionString("DefaultDbConnection"));
    options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
});


services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
    options.Password.RequireNonAlphanumeric = false;
    options.Password.RequireDigit = false;
    options.Password.RequireLowercase = false;
    options.Password.RequireUppercase = false;
    options.Password.RequiredLength = 6;
})
    .AddEntityFrameworkStores<GasdwahedDbContext>()
    .AddDefaultUI()
    .AddDefaultTokenProviders();
services.AddControllersWithViews();
services.AddMvc(options => options.EnableEndpointRouting = false);
services.AddRazorPages();
services.AddScoped<IUserClaimsPrincipalFactory<ApplicationUser>
    , ApplicationUserClaimsPrincipalFactory>();
services.AddSignalR();

//services.Configure<ForwardedHeadersOptions>(options =>
//{
//    options.KnownProxies.Add(IPAddress.Parse("192.168.1.220"));
//});

services.Configure<TwilioVerifySettings>(builder.Configuration.GetSection("Twilio"));

//JWT Generate Token

var appSettingsSection = builder.Configuration.GetSection("AppSettings");
services.Configure<AppSettings>(appSettingsSection);

var appSettings = appSettingsSection.Get<AppSettings>();
var key = Encoding.ASCII.GetBytes(appSettings.Secret);
services.AddAuthorization(options =>
{

    options.AddPolicy("Admin",
        authBuilder =>
        {
            authBuilder.RequireRole("Administrators");
        });

});
services.AddAuthentication(x =>
{
    x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(x =>
{

    x.RequireHttpsMetadata = false;
    x.SaveToken = true;
    x.TokenValidationParameters = new TokenValidationParameters
    {
        ValidateIssuerSigningKey = true,
        IssuerSigningKey = new SymmetricSecurityKey(key),
        ValidateIssuer = false,
        ValidateAudience = false
    };
});

services.ConfigureApplicationCookie(options =>
{
    options.ExpireTimeSpan = TimeSpan.FromDays(5);
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseForwardedHeaders(new ForwardedHeadersOptions
{
    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});

app.UseAuthentication();
app.UseAuthorization();

app.MapRazorPages();

app.MapControllerRoute(
    name: "MyArea",
    pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

c# asp.net .net model-view-controller .net-6.0
1个回答
0
投票

简单的挑衅性解决方案是:

1-右键单击有问题的文件。

2-选择属性。

3- 将“构建操作”更改为“内容”,而不是“无”或其他任何内容。

© www.soinside.com 2019 - 2024. All rights reserved.