2016-08-29 108 views
4

我有一個本地運行良好的ASP.NET Core應用程序。ASP.NET Core應用程序在發佈到Azure後不工作

然而,當我發佈(網絡部署)現場天青,我得到一個:You do not have permission to view this directory or page

我有一個默認的控制器和Startup.cs定義的路由:網在部署到Azure的

app.UseMvc(routes => 
      { 
       routes.MapRoute(
        name: "default", 
        template: "{controller}/{action}/{id?}", 
        defaults: new { controller = "Home", action = "Index" }); 
      }); 

的文件夾結構是這樣的:

|_ 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包含該文件)。

我也添加.UseIISIntegration()WebHostBuilder Startup.cs

public static void Main(string[] args) 
{ 
    new WebHostBuilder() 
     .UseKestrel() 
     .UseContentRoot(Directory.GetCurrentDirectory()) 
     .UseStartup<Startup>() 
     .UseIISIntegration() // This was missing 
     .Build() 
     .Run(); 
    } 

我現在可以IIS快遞本地運行(雖然我想這是IIS對開紅隼?),但如果公佈天青我得到錯誤: 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.

不知道如何適用於天青有關係嗎?

+0

你使用的是什麼版本的dotnet?另外,你有什麼包在project.json? –

+0

我已經添加了我的project.json文件,運行Core 1.0 RTM。 –

+0

@TedNyberg可能由於缺少'publishOptions'中的web.config而發生問題。試着像'[「wwwroot」,「Views」,「appsettings.json」,「appsettings。*。json」,「web.config」]一樣添加web.config。 –

回答

3

問題來自IIS集成/配置不足。

我不得不添加以下project.json

"tools": { 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" 
    } 

我還添加了postPublish腳本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" 
} 

這創建了一個網絡。配置文件,我作爲修改:

<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> 

最後我加入UseIISIntegrationWebHostBuilder

public static void Main(string[] args) 
{ 
    new WebHostBuilder() 
     .UseKestrel() 
     .UseContentRoot(Directory.GetCurrentDirectory()) 
     .UseStartup<Startup>() 
     .UseIISIntegration() // This was missing 
     .Build() 
     .Run(); 
    } 

標準發佈(網絡部署)從Visual Studio和該網站在Azure上的啓動情況良好(儘管在我的情況下,我還需要爲某些Gulp任務添加預發佈腳本)。

+1

今天早上我有同樣的確切問題,並在我的項目中進行了所有這些更改。唯一的區別是我正在通過VSTS進行部署。任何見解?獲取相同的錯誤消息 - 403:您無權查看此目錄或頁面。 – steamrolla

+1

對我來說,唯一的改變是將web.config更新爲:' –

+0

您可以在Azure部署後發佈文件夾結構嗎?我有同樣的問題,並想知道我的nuget包是否有問題。 – CanardMoussant

相關問題