【发布时间】:2020-05-28 16:27:20
【问题描述】:
我正在开发一个使用 Angular 7 作为前端、Net Core 3.0 作为后端的网络应用程序。在开发模式下一切正常,我可以从前端调用 URI,直接从浏览器和 Postman 以及 https://localhost:5001/api/controller/params
出于演示目的,我必须立即发布。从 CLI 和 Visual Studio (Mac) 来看,一切正常:使用路径 project/bin/Release/netcoreapp3.0/publish/所有 .dll 文件、web.config 等生成的文件夹。
但是,当我在 IIS 上发布时,如果我调用 https://appname.myserver.com/api/controller/params 或 http,浏览器会给我一个 404 错误。 如果我打电话给http://appname.myserver.com/,我会看到蓝色的 IIS 屏幕,其中包含不同语言的欢迎消息。
IIS 配置遵循此处的 Microsoft 说明:https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=visual-studio
我没有直接发布到 IIS,因为我无权访问服务器,但我确实远程监督了设置过程。
我查看了网络,有人建议在我的 Program.cs 文件中执行此操作:
namespace BackEnd
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseIISIntegration();
webBuilder.UseKestrel();
webBuilder.UseUrls("http://localhost:5000", "https://localhost:5001");
});
}
}
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=".\BackEnd.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
这是 applicationHosting.config:
<site name="backendv2.hawk-poslatinoamericana.com.mx" id="10" serverAutoStart="true">
<application path="/" applicationPool="No Managed Code" enabledProtocols="http">
<virtualDirectory path="/" physicalPath="C:\HostingSpaces\poslatino\backendv2.hawk-poslatinoamericana.com.mx\wwwroot" />
</application>
<bindings>
<binding protocol="https" bindingInformation="169.57.1.244:5001:backendv2.hawk-poslatinoamericana.com.mx" sslFlags="0" />
<binding protocol="http" bindingInformation="169.57.1.244:5000:backendv2.hawk-poslatinoamericana.com.mx" />
<binding protocol="http" bindingInformation="169.57.1.244:5000:www.backendv2.hawk-poslatinoamericana.com.mx" />
<binding protocol="https" bindingInformation="169.57.1.244:5001:www.backendv2.hawk-poslatinoamericana.com.mx" sslFlags="0" />
</bindings>
<logFile directory="C:\HostingSpaces\poslatino\backendv2.hawk-poslatinoamericana.com.mx\logs" enabled="true" />
<traceFailedRequestsLogging enabled="true" directory="C:\inetpub\logs\FailedReqLogFiles" maxLogFiles="50" />
<limits connectionTimeout="00:04:00" />
</site>
但到目前为止,运气不佳,我没有想法。
【问题讨论】:
-
您想在 iis 或 Kestrel 中托管您的应用程序?
-
我想在 IIS 上托管它
-
如果您在 IIS 上托管它,那么来自 IIS applicationHost.config 的相关 XML 元素也必须作为问题的一部分共享。
-
如果您收到带有消息的蓝屏,这意味着您指向的是您的机器/服务器,而不是您的应用程序。如果您已在 appname.myserver.com(这是您的 DNS 名称)上托管您的应用程序,那么您必须在您的 URL 中使用应用程序路径。例如appname.myserver.com/yourApplicationName_IIS/api/controller/…希望对你有帮助!
-
我只是放了 applicationHosting.config,只是有关网站的部分,如果需要该文件中的其他内容,请告诉我。
标签: c# angular asp.net-core iis .net-core