Ted*_*erg 5 azure webdeploy kudu asp.net-core
我有一个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" });
});
Run Code Online (Sandbox Code Playgroud)
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?)
Run Code Online (Sandbox Code Playgroud)
想知道我应该在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/"
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:
首先,我错过了Microsoft.AspNetCore.Server.IISIntegration
NuGet包.当我添加它时,我还在web.config
站点根目录中有一个文件(我通过它包含project.json
).
我还添加.UseIISIntegration()
到我WebHostBuilder
的Startup.cs:
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
Run Code Online (Sandbox Code Playgroud)
我现在可以在本地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?
问题来自于 IIS 集成/配置不足。
我必须添加以下内容project.json
:
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
}
Run Code Online (Sandbox Code Playgroud)
我还添加了一个用于 IIS 发布的postPublish脚本:
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
Run Code Online (Sandbox Code Playgroud)
我还添加了 Microsoft.AspNetCore.Server.IISIntegration NuGet 包:
"dependencies": {
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0"
}
Run Code Online (Sandbox Code Playgroud)
这创建了一个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>
Run Code Online (Sandbox Code Playgroud)
最后,我将UseIISIntegration添加到我的WebHostBuilder中:
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
Run Code Online (Sandbox Code Playgroud)
来自 Visual Studio 的标准发布(Web 部署)和网站在 Azure 上启动得很好(尽管在我的例子中,我还必须为某些 Gulp 任务添加预发布脚本)。
归档时间: |
|
查看次数: |
4034 次 |
最近记录: |