已发布的.NETCORE WEB API无法正常工作的是配置可能会丢失。 404
我有一个简单的API,当我在Visual Studio 2019中运行API时,它正常工作,我使用Swagger来确保它有效。无论是调试还是发布,我都可以使用ISS Express或Kestrel。虽然它是从IDE起作用的,但它起作用。
当我在Visual Studio IDE之外使用它时,它不起作用。是找不到404。似乎无法正确读取配置。我尝试了很多事情(命令行dotnet myapi.dll,将其发布并在服务器中尝试…),但是如果在VS之外使用,则无效。我猜想它以某种方式无法正确读取配置,因为在所有尝试(IDE之外)中,最终都使用默认端口(5000和5001)。
这可能很简单。我认为丢失的配置是plunchersettings中的一种
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53907/",
"sslPort": 44369
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyAPI": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:44369;http://localhost:5000"
}
}
}
。
编辑...
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="aspNetCore"/>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
<!-- Config de ultima solucion https://stackoverflow.com/questions/4022434/how-to-set-the-maxallowedcontentlength-to-500mb-while-running-on-iis7-->
<system.web>
<!-- ~ 2GB -->
<httpRuntime maxRequestLength="2147483647" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<!-- ~ 4GB -->
<requestLimits maxAllowedContentLength="4294967295" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
为了使事情变得更简单,我现在正在使用kestel(只需为当前项目选择输入点)。然后,调试的作用是编译并执行调试/*。EXE,它在配置中设置的44369在44369中运行。
但是,如果我转到该文件夹并单击exe,它在端口5001中工作。到此https:// localhost:5001/swagger/index.html现在找不到404。
I have a simple API, when I run the API in Visual Studio 2019 it works perfectly, I'm using swagger to see that it worked. Doesn’t matter if its debug or release and I can use ISS Express or Kestrel. While it's called from the IDE it works.
When I use it outside of Visual Studio IDE it does not work. Is a 404 not found. It seems to not read properly the configuration. I tried many things (command line dotnet MyAPI.dll, publishing it and try it in a server…) but if used outside of VS , it does not work. I’m guessing somehow It does not read the properly the configuration because in all tries (outside of IDE) it ends up using default ports (5000 and 5001).
It is probably something simple. The configuration I believe is lost is the one in launcherSettings.json that you can see here:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53907/",
"sslPort": 44369
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyAPI": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:44369;http://localhost:5000"
}
}
}
Any idea what I'm doing wrong?
Edit...
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="aspNetCore"/>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
<!-- Config de ultima solucion https://stackoverflow.com/questions/4022434/how-to-set-the-maxallowedcontentlength-to-500mb-while-running-on-iis7-->
<system.web>
<!-- ~ 2GB -->
<httpRuntime maxRequestLength="2147483647" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<!-- ~ 4GB -->
<requestLimits maxAllowedContentLength="4294967295" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
To keep things more simple I'm using now Kestel (simply picking the entry point for the current project). Then what debug does is compile and execute the Debug/*.exe, it runs in 44369 as set in the config.
However if I go to that folder and doble click on the exe it works in port 5001. To this https://localhost:5001/swagger/index.html the response is now a 404 Not Found.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我正在回答自己的问题。
Well, I'm answering my own question with the findings I've got.