简答
但是当我发布它并尝试打开时,我看到的只是不停地加载空白页面。
当我们的应用无法与应用发布运行时 (dnx.exe) 时,就会发生这种情况。
讨论
有多种方法可以将 ASP.NET Core rc1 应用程序发布到 Azure Web 应用程序。其中包括使用 Git 进行持续部署和使用 Visual Studio 发布。发布您的存储库内容以获得特定帮助。
该示例是一个 ASP.NET Core rc1 应用程序,通过 GitHub 持续部署部署到 Azure Web 应用程序。这些是重要文件。
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。
<?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 服务器的依赖。设置将启动 Kestrel 的 web 命令。使用dnx451 作为目标框架。有关针对 dnxCore50 的其他工作,请参见下文。
{
"dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnx451": { }
}
}
app/Startup.cs
包括Configure 方法。这个添加了一个非常简单的响应处理程序。
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.");
});
}
}
}
.deployment(可选)
如果您的应用不在存储库根目录中,请告诉 Azure Web 应用哪个目录包含该应用。
[config]
project = app/
global.json(可选)
如果您希望以 .NET Core 为目标,请告诉 Azure 我们希望以它为目标。添加此文件后,我们可以将 project.json 中的 dnx451 条目替换(或补充)为 dnxCore50。
{
"sdk": {
"version": "1.0.0-rc1-update1",
"runtime": "coreclr",
"architecture": "x64"
}
}