ASP.NET核心应用程序在发布到Azure后不工作
我有一个ASP.NET核心应用程序,在本地运行良好 但是,当我将网站发布到Azure时,我得到一个403:ASP.NET核心应用程序在发布到Azure后不工作,azure,asp.net-core,webdeploy,kudu,Azure,Asp.net Core,Webdeploy,Kudu,我有一个ASP.NET核心应用程序,在本地运行良好 但是,当我将网站发布到Azure时,我得到一个403:您没有查看此目录或页面的权限 我在Startup.cs中定义了默认控制器和路由: app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{act
您没有查看此目录或页面的权限
我在Startup.cs中定义了默认控制器和路由:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
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中的WebHostBuilder
中添加了.useisintegration()
:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
publicstaticvoidmain(字符串[]args)
{
新WebHostBuilder()
.UseKestrel()
.UseContentRoot(目录.GetCurrentDirectory())
.UseStartup()
.UseIISIntegration()//缺少此项
.Build()
.Run();
}
我现在可以在本地的IIS Express上运行它(虽然我猜它是IIS在红隼面前?),但是当发布到Azure时,我得到了错误:
HTTP错误502.5-进程失败
Azure中的事件日志状态为:无法使用命令行“%LAUNCHER\u PATH%”“%LAUNCHER\u ARGS%”启动进程,错误代码为“0x80070002”。
根据文档,故障排除步骤为:
<>代码>如果服务器在安装服务器托管包时没有Internet访问,则当安装程序无法在微软上获得在线的Visual C++ 2015可重分发(X64)包时,将出现此异常。您可以从Microsoft下载中心获得软件包的安装程序。
不确定这如何适用于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"
}
这创建了一个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>
最后,我将useisintegration添加到我的WebHostBuilder:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
publicstaticvoidmain(字符串[]args)
{
新WebHostBuilder()
.UseKestrel()
.UseContentRoot(目录.GetCurrentDirectory())
.UseStartup()
.UseIISIntegration()//缺少此项
.Build()
.Run();
}
Visual Studio的标准发布(Web部署)和网站在Azure上的启动情况都很好(尽管在我的情况下,我还必须为一些吞咽任务添加一个预发布脚本)。您使用的是什么版本的dotnet?另外,project.json中有哪些包?我已经添加了我的project.json文件,运行Core 1.0 RTM。@TedNyberg问题可能是由于
publishOptions
中缺少web.config。尝试添加web.config,如“[”wwwroot“,”Views“,”appsettings.json“,”appsettings.*.json“,”web.config“]`。我以前有过,但项目中没有web.config?添加IIS集成NuGet包时出现了web.config文件。:)你把我带到了正确的方向,问题已经解决了!谢谢@ademcaglin!今天早上我遇到了同样的问题,在我的项目中进行了所有这些更改。唯一的区别是我是通过VST部署的。有什么见解吗?收到与您相同的错误消息-403:您没有查看此目录或页面的权限
。对我来说,唯一的更改是将web.config更新为:
部署Azure后,您能否在Azure上发布文件夹结构?我也有同样的问题,不知道我的nuget软件包是否有问题。