我有一个在本地运行良好的ASP.NET核心应用程序。
但是,当我发布(Web部署)网站到Azure时,我得到 403 :You do not have permission to view this directory or page
。
我有一个默认控制器和一个在 Startup.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门户中找出什么来了解什么是错误的想法?
我的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
包含该文件)。
我还在 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 本地运行它(虽然我猜它是面向Kestrel的IIS?),但是当发布到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 ,
答案 0 :(得分:3)
问题来自IIS集成/配置不足。
我必须将以下内容添加到project.json
:
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
}
我还为IIS发布添加了 postPublish 脚本:
"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"
}
这创建了一个 web.config 文件,我必须将其修改为:
<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>
最后,我将 UseIISIntegration 添加到我的 WebHostBuilder :
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
一些来自Visual Studio的标准发布(Web部署),该网站在Azure上运行得很好(尽管在我的情况下我还必须为某些人添加预发布脚本Gulp任务)。