標籤:程式 art startup ogr test deploy uil rtu undle
摘要
最近項目中,嘗試使用asp.net core開發,在部署的時候,考慮現有硬體,只能部署在windows上,linux伺服器暫時沒有。
部署注意事項
代碼中啟用iis和Kestrel
public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .UseApplicationInsights() .Build(); }
在服務端安裝
.NET Core Windows Server 託管捆綁包
捆綁包可安裝 .NET Core 運行時、.NET Core 庫和 ASP.NET Core 模組。 該模組建立 IIS 與 Kestrel 伺服器之間的反向 Proxy。 如果系統沒有 網際網路連線,請先擷取並安裝 Microsoft Visual C++ 2015 Redistributable,再安裝 .NET Core Windows Server 託管捆綁包。
重啟系統,或從命令提示字元處依次執行 net stop was /y 和 net start w3svc。 重新啟動 IIS 將選取安裝程式對系統 PATH 所作的更改。
發布
使用vs發布或者使用命令,這裡由於使用vs2017開發,就直接用vs發布了
在服務端建立網站
修改應用池CLR為No Managed Code
可以下面建立子網站test
確認進程模型標識擁有適當的許可權。
如果將應用池的預設標識(“進程模型” > “標識”)從 ApplicationPoolIdentity 更改為另一標識,請驗證新標識擁有所需的許可權,可訪問應用的檔案夾、資料庫和其他所需資源。例如,應用池需要對檔案夾的讀取和寫入許可權,以便應用在其中讀取和寫入檔案。
常見錯誤
如果通過ip和連接埠訪問,報500錯誤,但在伺服器上 通過dotnet \xxxxx.dll可以啟動kestrel,並可以通過http:\\localhost:5000進行訪問,一般可以通過修改網站目錄許可權進行解決。至少可以讀寫的許可權。
其他錯誤,可以參考
https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/iis/troubleshoot
Asp.net core使用IIS在windows上進行託管