在IIS上托管Asp.Net Core 2

时间:2018-04-12 05:54:39

标签: asp.net iis hosting asp.net-core-2.0 iis-express

我的应用程序在ApplicationName和IISExpress中通过Visual Studio在Release / Debug模式下启动时运行良好。

但是一旦部署到IIS并启动,我就无法访问主页(家庭控制器),也有导航栏问题和JQuery问题。我已经在调试/发布模式下发布了应用程序,但无济于事。

我的问题主要是如何解决这个问题?应用程序的运行方式与iisexpress本地运行的方式相同吗?即使文件丢失(如在调试/发布环境中),Home控制器也应该是正确访问的?

非常感谢任何帮助,并等待根据评论发布更多信息和日志。

编辑1(包括Startup.cs):

using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using MTAClassLib.Configuration;
using System.IO;

namespace MTALib
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var RoleManager = services.GetRequiredService<RoleManager<IdentityRole>>();
                UserRoleSeed.Seed(RoleManager).Wait();
            }
            BuildWebHost(args).Run();
        }
    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .Build();
     }
}

3 个答案:

答案 0 :(得分:4)

在IIS上运行ASP.Net Core 2时,我遇到了同样的问题。我不得不

  1. 安装.NET Core主机捆绑包。如果尚未下载,可以https://aka.ms/dotnetcore-2-windowshosting下载。
  2. 安装主机捆绑包后,在命令行窗口中运行IISReset
  3. 确保您的project.cs BuildWebHost方法如下所示

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();}
    
  4. 我不必将.NET CLR版本的应用程序池更改为“无托管代码”。仍为“ .Net CLR版本v4.0.30319”

  5. 编辑web.config并将stdoutLogEnabled更改为true。
  6. 在发布的文件夹中手动创建日志文件夹。

这解决了我的问题。

答案 1 :(得分:0)

ASP.NET Core 2.0的托管与ASP.NET托管有点不同。

您需要Install the .NET Core Hosting Bundle

另外,请确保应用程序池&gt;&gt; .NET CLR版本应为无托管代码

有关详细信息,请参阅Host ASP.NET Core on Windows with IIS

enter image description here

答案 2 :(得分:0)

安装“ dotnet-hosting-2.1.2-win.exe”并重置IIS已为我解决了该问题。