ASP.NET Core 应用程序在发布到 Azure 后无法运行

2023-12-05

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

然而,当我publish(Web 部署)将站点部署到 Azure,我得到403: You do not have permission to view this directory or page.

我有一个默认控制器和一个定义的路由启动.cs:

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

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

|_ 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 门户中查找什么来找出问题所在吗?

My project.json file:

{
  "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/"
  }
}

Edit:

其一,我错过了Microsoft.AspNetCore.Server.IISIntegrationNuGet 包。当我添加它时,我还得到了一个web.config站点根目录中的文件(我通过project.json).

我还添加了.UseIISIntegration() to my WebHostBuilder in 启动.cs:

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

我现在可以运行它IIS 快递本地(虽然我猜它是 IIS 前面的 Kestrel?),但是当发布到 Azure 时我收到错误:HTTP Error 502.5 - Process Failure

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

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

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, 尽管?


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

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

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

我还添加了一个发布后IIS发布脚本:

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

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

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

这创建了一个网络配置文件,我必须将其修改为:

<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>

最后我添加了使用IIS集成 to my 网络主机生成器:

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

一个标准Publish(Web 部署)从 Visual Studio 和网站在 Azure 上启动得很好(尽管在我的情况下,我还必须添加一个预发布一些 Gulp 任务的脚本)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ASP.NET Core 应用程序在发布到 Azure 后无法运行 的相关文章

随机推荐