แอป ASP.NET MVC Core ที่เผยแพร่ไปยัง IIS ส่งคืนหน้าว่าง

สภาพแวดล้อม: Windows 10 (อัปเกรดจาก Win 8.1), IIS เวอร์ชัน 10.0.10586.0, VS2015-อัปเดต 3 พร้อมแพตช์ล่าสุดที่เผยแพร่เมื่อวันที่ 16 กันยายน 2016 SQLServer EXPRESS 2014, AspNetCoreModule ติดตั้งด้วย ASP.NET Core Server Hosting Bundle, เวอร์ชัน PowerShell: 5.0.10586.494

ฉันเผยแพร่แอป ASP.NET MVC Core ไปยัง IIS ตาม บทความนี้ และปฏิบัติตามข้อกำหนดที่อธิบายไว้ในบทความ แต่เมื่อฉันเรียกดูแอปจาก IIS ฉันจะได้รับ localhost/myASPCorePublishedDir เป็น URL ในเบราว์เซอร์โดยไม่มีข้อผิดพลาด แต่หน้าเว็บกลับกลายเป็นว่างเปล่า ด้านล่างนี้คือภาพหน้าจอการตั้งค่าของฉัน สิ่งที่ฉันอาจหายไป?

การตั้งค่า AppPool ของฉัน:

ป้อนคำอธิบายรูปภาพที่นี่

AspNetCoreModule ได้รับการติดตั้งบนเครื่องแล้ว:

ป้อนคำอธิบายรูปภาพที่นี่

web.config ในรูทของแอป:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <!--
    Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
  -->

  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>

โครงการ json:

{
  "userSecretsId": "aspnet-ABCTest-6af8ade3-87ff-4468-a9ce-8bb69c696ab8",

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": {
      "version": "1.0.0",
      "type": "build"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    }
  },

  "tools": {
    "BundlerMinifier.Core": "2.0.238",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

StartUp.cs:

public class Startup
{
    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();
        }

        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)
    {
        var connection = @"Server=myWin10Machine\SQLEXPRESS;Database=mySQLDb;Trusted_Connection=True;";
        services.AddDbContext<myASPCoreContext>(options => options.UseSqlServer(connection));

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

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

        services.AddMvc();

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

    // 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();

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

        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=Home}/{action=Index}/{id?}");
        });
    }
}

comment
ตรวจสอบตัวแปร ASPNETCORE_ENVIRONMENT ของคุณและ AppSettings.json ที่เกี่ยวข้อง   -  person Sanket    schedule 26.09.2016


คำตอบ (1)


ข้อจำกัดความรับผิดชอบ: เครดิตสำหรับโซลูชันนี้มอบให้กับ @JesonMartajaya และผู้แต่ง โครงการนี้จาก Microsoft (โปรดดูไฟล์ web.config พร้อมความคิดเห็น) หลังจากอ่านลิงก์ทั้งสองนี้แล้ว ฉันได้ทำการเปลี่ยนแปลง web.config ต่อไปนี้ (ดังที่แสดงด้านบน) และตอนนี้ก็ใช้งานได้แล้ว:

ฉันแทนที่ %LAUNCHER_PATH% เป็น dotnet และ %LAUNCHER_ARGS% เป็น myProjectName.dll

person nam    schedule 26.09.2016