发布到Azure后ASP.NET Core应用无法正常工作 [英] ASP.NET Core app not working after publish to Azure

查看:107
本文介绍了发布到Azure后ASP.NET Core应用无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET Core应用程序,该应用程序在本地运行良好.

I have an ASP.NET Core app which is running fine locally.

但是,当我发布(通过Web部署)网站到Azure时,却得到 403 :You do not have permission to view this directory or page.

However, when I publish (Web Deploy) the site to Azure, I get a 403: You do not have permission to view this directory or page.

我有一个默认控制器和一个在 Startup.cs 中定义的路由:

I have a default controller and a route defined in Startup.cs:

app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });
            });

Web部署到Azure之后的文件夹结构如下:

The folder structure after web deploy to Azure looks like:

|_ home
  |_ site
    |_ wwwroot (contains DLL's and files specified through 'publishOptions' in project.json)
      |_ wwwroot (the contents of the 'wwwroot' folder I have in Visual Studio)
      |_ Views (contains MVC views)
      |_ refs (contains referenced DLLs, I think?)

关于我应该在project.json或Kudu门户中查找什么的任何想法,以找出问题所在?

Any idea of what I should look for in project.json or the Kudu portal to figure out what's wrong?

我的project.json文件:

{
  "title": "My Web App",
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "compile": {
      "exclude": [ "bin/**", "obj/**", "node_modules/" ]
    }
  },
  "publishOptions": {
    "include": [ "wwwroot", "Views", "appsettings.json", "appsettings.*.json" ]
  },
  "scripts": {
    "prepublish": [ "jspm install", "gulp build" ]
  },
  "dependencies": {
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "System.IO.FileSystem": "4.0.1"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        },
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
      },
      "imports": "dnxcore50"
    }
  },
  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel --server.urls=http://*:8000/"
  }
}

有一个我错过了Microsoft.AspNetCore.Server.IISIntegration NuGet软件包.当我添加它时,我在站点根目录中也有一个web.config文件(我通过project.json包含了该文件).

For one, I was missing the Microsoft.AspNetCore.Server.IISIntegration NuGet package. When I added it, I also got a web.config file in the site root (which I included through project.json).

我还在 Startup.cs 中将.UseIISIntegration()添加到了WebHostBuilder:

public static void Main(string[] args)
{
   new WebHostBuilder()
      .UseKestrel()
      .UseContentRoot(Directory.GetCurrentDirectory())
      .UseStartup<Startup>()
      .UseIISIntegration() // This was missing
      .Build()
      .Run();
   }

我现在可以在本地 IIS Express 上运行它(尽管我猜它是IIS朝向Kestrel的IIS?),但是在发布到Azure时出现错误: HTTP Error 502.5 - Process Failure

I can now run it on IIS Express locally (although I guess it's IIS fronting Kestrel?), but when published to Azure I get error: HTTP Error 502.5 - Process Failure

Azure中的事件日志状态:Failed to start process with commandline '"%LAUNCHER_PATH%" %LAUNCHER_ARGS%', ErrorCode = '0x80070002'.

The event log in Azure states: Failed to start process with commandline '"%LAUNCHER_PATH%" %LAUNCHER_ARGS%', ErrorCode = '0x80070002'.

根据文档,故障排除步骤为:

According to the documentation, the troubleshooting step is:

If the server does not have Internet access while installing the server hosting bundle, this exception will ensue when the installer is prevented from obtaining the Microsoft Visual C++ 2015 Redistributable (x64) packages online. You may obtain an installer for the packages from the Microsoft Download Center.

虽然不确定这对 Azure 有何作用?

Not sure how this applies to Azure, though?

推荐答案

问题来自IIS集成/配置不足.

The problem came from insufficient IIS integration/configuration.

我必须在project.json中添加以下内容:

I had to add the following to project.json:

"tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  }

我还为IIS发布添加了 postPublish 脚本:

I also added a postPublish script for IIS publishing:

"scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }

我还添加了Microsoft.AspNetCore.Server.IISIntegration NuGet包:

I also added the Microsoft.AspNetCore.Server.IISIntegration NuGet package:

"dependencies": {
  "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0"
}

这创建了一个 web.config 文件,我必须将其修改为:

This created a web.config file, which I had to modify as:

<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath=".\My.Web.App.dll" arguments="" forwardWindowsAuthToken="false" stdoutLogEnabled="true" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
  </system.webServer>
</configuration>

最后,我在 WebHostBuilder 中添加了 UseIISIntegration :

public static void Main(string[] args)
{
   new WebHostBuilder()
      .UseKestrel()
      .UseContentRoot(Directory.GetCurrentDirectory())
      .UseStartup<Startup>()
      .UseIISIntegration() // This was missing
      .Build()
      .Run();
   }

来自Visual Studio的标准发布(网络部署),并且网站在Azure上开始正常运行(尽管就我而言,我还必须为某些内容添加预发布脚本) Gulp任务).

A standard Publish (Web Deploy) from Visual Studio and the website started just fine on Azure (although in my case I also had to add a prepublish script for some Gulp tasks).

这篇关于发布到Azure后ASP.NET Core应用无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆