且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将ASP.NET 5(ASP.NET Core)应用程序部署到Azure的问题

更新时间:2022-01-04 22:18:47

简短回答

但是当我发布并尝试打开它时,我只会看到不停地加载空白页面.

But when I publish it and try to open, I see just non-stop loading of empty page.

当我们的应用无法通过应用发布发布运行时(dnx.exe)时,就会发生这种情况.

This happens when our app fails to publish the runtime (dnx.exe) with the application.

有几种方法可以将ASP.NET Core rc1应用发布到Azure Web应用.其中包括使用Git进行连续部署以及使用Visual Studio进行发布.发布您存储库的内容以获取特定帮助.

There are several ways to publish ASP.NET Core rc1 apps to an Azure Web App. These include continuous deployment with Git and publishing with Visual Studio. Post your repository's contents for specific help.

该示例是一个通过GitHub连续部署将ASP.NET Core rc1应用程序部署到Azure Web应用程序的示例.这些是至关重要的文件.

The example is an ASP.NET Core rc1 app, deployed to an Azure Web App, via GitHub continuous deployment. These are the vital files.

app/
    wwwroot/
        web.config
    project.json
    startup.cs
.deployment           <-- optional: if your app is not in the repo root 
global.json           <-- optional: if you need dnxcore50 support

app/wwwroot/web.config

添加HttpPlatformHandler.配置它以将所有请求转发到DNX进程.换句话说,告诉Azure Web应用程序使用DNX.

Add the HttpPlatformHandler. Configure it to forward all requests to a DNX process. In other words, tell the Azure Web app to use DNX.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" 
           path="*" verb="*" 
           modules="httpPlatformHandler" 
           resourceType="Unspecified"/>
    </handlers>
    <httpPlatform 
         processPath="%DNX_PATH%" 
         arguments="%DNX_ARGS%" 
         stdoutLogEnabled="false" 
         startupTimeLimit="3600"/>
  </system.webServer>
</configuration>

app/project.json

包括对Kestrel服务器的依赖性.设置web命令以启动Kestrel.使用dnx451作为目标框架.参见下文,了解针对dnxCore50的其他工作.

Include a dependency on the Kestrel server. Set a web command that will startup Kestrel. Use dnx451 as the target framework. See below for the additional work to target dnxCore50.

{
  "dependencies": {
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": { }
  }
}

app/Startup.cs

包括Configure方法.这增加了一个非常简单的响应处理程序.

Include the Configure method. This one adds an extremely simple response handler.

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;

namespace WebNotWar
{
    public class Startup
    {
        public void Configure(IApplicationBuilder app)
        {
            app.Run(async (context) =>
            {
                await context.Response.WriteAsync(
                    "Hello from a minimal ASP.NET Core rc1 Web App.");
            });
        }
    }
}

.部署(可选)

如果您的应用程序不在存储库根目录中,请告诉Azure Web App哪个目录包含该应用程序.

If your app is not in the repositories root directory, tell the Azure Web App which directory contains the app.

[config]
project =  app/

global.json (可选)

如果要定位.NET Core,请告诉Azure我们要定位它.添加此文件后,我们可以用dnxCore50替换(或补充) project.json 中的dnx451条目.

If you would like to target .NET Core, tell Azure that we want to target it. After adding this file, we can either replace (or complement) the dnx451 entry in our project.json with dnxCore50.

{
  "sdk": {
    "version": "1.0.0-rc1-update1",
    "runtime": "coreclr",
    "architecture": "x64"
  }
}