已經嘗試了HTTP 錯誤 500.30 - ASP.NET Core 5 應用程式無法啟動和其他類似帖子中發現的建議,但運氣不佳。
我的 API 在 VS2019 中與 IIS Express 一起運行時運行良好,但發布后無法啟動。
這是我的 web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MyApi.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
嘗試了行程內和行程外,提供的環境變數沒有區別。
代碼部署到 C:\inetpub\wwwroot\MyApi
IIS_IUSRS 已被授予對 wwwroot 檔案夾的讀/寫訪問權限
這是我在 VS 專案中作業的 Lunchsettings.json 檔案
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "https://localhost:44307",
"sslPort": 44307
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyApi": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
這是我的程式.cs
public class Program
{
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
_ = webBuilder.UseStartup<Startup>();
})
.ConfigureServices(services =>
{
_ = services.AddHostedService<MyApiWorker>().Configure<EventLogSettings>(config =>
{
config.LogName = "My API";
config.SourceName = "My API";
});
});
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
}
/inetpub/logs/logfiles 中的 IIS 日志并不是那么有用(4443 是我添加到 IIS 時使用的埠)。
#Software: Microsoft Internet Information Services 10.0
#Version: 1.0
#Date: 2021-10-27 09:31:01
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2021-10-27 09:31:01 ::1 GET / - 4443 - ::1 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 - 500 0 2147500037 4
2021-10-27 09:31:07 ::1 GET / - 4443 - ::1 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 - 500 0 2147500037 0
2021-10-27 09:32:39 ::1 GET /swagger - 4443 - ::1 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 - 500 0 2147500037 0
2021-10-27 09:36:45 ::1 GET / - 4443 - ::1 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 - 500 0 2147500037 0
任何想法將不勝感激。我似乎找不到任何有意義的日志,并且應用程式輸出的日志從不發布任何內容。
EDIT: Application Pool is No Managed Code Have installed dotnet-hosting-5.0.11-win.exe and rebooted and restarted IIS multiple times.
Event Log shows: Application '/LM/W3SVC/1/ROOT' with physical root 'C:\inetpub\wwwroot\myapi' failed to load coreclr. Exception message: Managed server didn't initialize after 120000 ms.
EDIT 2 Now getting this in the Event Logs:
The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID
{3480A401-BDE9-4407-BC02-798A866AC051}
and APPID
{30AD8C8E-AE85-42FA-B9E8-7E99E3DFBFC5}
to the user IIS APPPOOL\DotNetCore SID (S-1-5-82-2530134163-791093599-2246298441-3166710890-3969430272) from address LocalHost (Using LRPC) running in the application container Unavailable SID (Unavailable). This security permission can be modified using the Component Services administrative tool.
All stdout logs 0kb empty files
EDIT 3 I can also go to the folder and run it by double-clicking the exe, but for some reason, IIS will not. This makes no sense. All I get is this error:
Application '/LM/W3SVC/1/ROOT' with physical root 'C:\inetpub\wwwroot\myapi\' failed to load coreclr. Exception message:
Managed server didn't initialize after 120000 ms.
Extending timeout doesn't help either, when manually executing it takes seconds to get up and running.
EDIT 4 I had some Google Gmail functions in the API to send out emails on errors. Seems they were causing a problem. Removed all traces of the google stuff, and it no longer takes minutes to start. I suspect this was because Google was trying to get IIS to accept terms to use Gmail, but that obviously cannot happen.
Now that is out of the way, I am still getting a new error:
Application '/LM/W3SVC/1/ROOT' with physical root 'C:\inetpub\wwwroot\myapi\' has exited from Program.Main with exit code = '0'. Please check the stderr logs for more information.
But no stderr messages to be found, but at least the error is different.
uj5u.com熱心網友回復:
我能夠在我的 Windows IIS 上托管。
先決條件:您需要在服務器上安裝 .Net Core Hosting Bundle。
在 IIS 管理器中,
在 IIS 中創建新網站并指向您發布代碼的檔案夾。IIS網站
創建網站時,會自動創建在 ApplicationPoolIdentity 上運行的應用程式池。確保 .Net CLR 版本是“無托管代碼”應用程式池
重置 IIS
瀏覽應用程式 url:http://:port/<controllername/route>
uj5u.com熱心網友回復:
- 請確保您已在服務器上安裝了 .net 核心
- 將您的應用程式池設定為無托管代碼
- 如果仍然無法正常作業,請檢查錯誤日志
我按照這些步驟https://dotnetblog.asphostportal.com/how-to-publish-asp-net-core-blazor-application-to-iis/和我的應用程式完美地作業。
uj5u.com熱心網友回復:
好的,所以我在沒有任何有用日志的情況下弄清楚了。
它不會運行 Google 身份驗證這一事實讓我開始考慮是否需要以自己的身份運行應用程式池,因此我將應用程式池身份設定為我的用戶帳戶。沒有骰子。于是我找到了這篇文章:ASP.NET Core Web 3.1 - IIS Express can fetch data from localdb but local IIS can not
遵循他們的建議,現在應用程式報告開始正常。我可以看到它正在運行的日志并且可以訪問端點。
還能夠為電子郵件通知添加回我的 Google 身份驗證。一切正常。
我還借此機會將應用程式池的超時設定為 0,并將其設定為啟動模式:始終運行。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/346046.html
標籤:c# asp.net-mvc asp.net-core-5.0
上一篇:我想知道如何在使用Bootstrap框架設計我的按鈕時使用@Htmlhelper將值傳遞給控制器
下一篇:MVC屬性路由與查詢引數不起作用
