首页 > 解决方案 > ASP.NET 核心在发布到文件夹并将其添加到 IIS 时默认主页/索引返回空白页

问题描述

当我将网页发布到文件夹并将其添加到 IIS 时,一切正常,除了登录时它重定向我的默认页面。什么都没有加载它只是这个

<html>
<head>
    <link rel="alternate stylesheet" type="text/css" href="resource://content-accessible/plaintext.css" title="Prelomi dolge vrstice">
</head>
<body>
    <pre></pre>
</body>
</html>

布局没有加载,什么都没有。

这是我的 Startup.cs

public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

        if (env.IsDevelopment())
        {
            // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
            builder.AddUserSecrets<Startup>();

            // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
            builder.AddApplicationInsightsSettings(developerMode: true);
        }

        builder.AddEnvironmentVariables();
        Configuration = builder.Build();
    }

    public IConfigurationRoot Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddApplicationInsightsTelemetry(Configuration);

        //var connection = @"Server=localhost\SQLEXPRESS;Database=endoIS;Integrated Security=False;MultipleActiveResultSets=true;Persist Security Info=False;User ID=admin;Password=000000";
        //services.AddDbContext<EndoContext>(options => options.UseSqlServer(connection));

        // services.AddIdentity<ApplicationUser, IdentityRole>()
        //    .AddEntityFrameworkStores<EndoContext>()
        //    .AddDefaultTokenProviders();

        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

        services.AddMvc();
        services.AddScoped<SignInManager<ApplicationUser>, SignInManager<ApplicationUser>>();

        services.Configure<PasswordHasherOptions>(options =>

            options.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2

        );
        // Add application services.
        services.AddTransient<IEmailSender, AuthMessageSender>();
        services.AddTransient<ISmsSender, AuthMessageSender>();

        services
        .AddMvc()
        .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());

        // Add Kendo UI services to the services container
        services.AddKendo();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();

        app.UseApplicationInsightsRequestTelemetry();

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
            app.UseBrowserLink();
        }
        else
        {
            app.UseExceptionHandler("/Home/Index");
        }

        app.UseApplicationInsightsExceptionTelemetry();

        app.UseStaticFiles();

        app.UseIdentity();

        // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Evidenca}/{action=Index}/");
        });

        // Configure Kendo UI
        app.UseKendo(env);
    }

即使我尝试通过调用控制器和方法来进入默认页面,它也是一样的

标签: c#htmliisasp.net-core-2.1

解决方案


推荐阅读