简体   繁体   English

.NET核心Web API作为Azure应用程序服务上的虚拟应用程序

[英].NET core web API as virtual application on Azure app service

I have a .NET core 2.0 web application running successfully as an Azure app service. 我有一个.NET core 2.0 Web应用程序作为Azure应用程序服务成功运行。

To save money/complication, I would like to run its public API on the same domain, as a virtual application ie www.mysite.com/api 为了省钱/复杂,我想在一个域上运行它的公共API,就像一个虚拟应用程序,即www.mysite.com/api

However, when I release to the virtual application, and then try to access it, I simply get an error message saying: 但是,当我释放到虚拟应用程序,然后尝试访问它时,我仅收到一条错误消息,内容为:

"The page cannot be displayed because an internal server error has occurred." “由于发生内部服务器错误,因此无法显示该页面。”

I am an experienced .NET framework developer, but this is my first .NET core project, so I am a little unsure how to debug this. 我是一位经验丰富的.NET Framework开发人员,但这是我的第一个.NET核心项目,因此我不确定如何调试它。

Just to confirm, I have a .NET core website and a .NET core web API, where the web API is meant to live in the "/api" virtual application. 只是为了确认一下,我有一个.NET核心网站和一个.NET核心Web API,其中Web API应驻留在“ / api”虚拟应用程序中。 I have setup the virtual application within the Azure app service as "site\\api" (with the main website being "site\\wwwroot") 我已将Azure应用程序服务中的虚拟应用程序设置为“ site \\ api”(主网站为“ site \\ wwwroot”)

The API has its own web.config etc. as expected. 该API具有预期的自己的web.config等。 I am guessing this is all caused by some config I haven't done, but I am unsure as to what exactly. 我猜这都是由我尚未完成的某些配置引起的,但是我不确定到底是什么。

The problem is that you "Sub-Application" has an web.config file generated that has a duplicate entry in it the parent web.config already has: 问题是您“子应用程序”生成了一个web.config文件,其中父web.config已经具有一个重复的条目:

<system.webServer>
<handlers>
  <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>

See this article here: https://github.com/aspnet/IISIntegration/issues/190 请参阅此处的文章: https : //github.com/aspnet/IISIntegration/issues/190

In your Startup.cs, you will probably have something like: 在您的Startup.cs中,您可能会有类似以下内容:

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}

Just comment out the if , and you will get the developer exception page in 'production'. 只需注释掉if ,您将在“生产”中获得开发人员例外页面。

That might give you a clue as to what the real problem is. 这可能为您提供了真正问题所在的线索。

In addition to what @Neil said, enable startup errors because the application might already fail to boot which will cause no developer exception page to be shown at all. 除了@Neil所说的以外,还要启用启动错误,因为应用程序可能已经无法启动,这将导致根本不显示开发人员异常页面。

In your program.cs adjust the webhost build process 在您的program.cs中调整Webhost的构建过程

        return WebHost.CreateDefaultBuilder(args)
            .CaptureStartupErrors(true) // add this line
            .UseSetting(WebHostDefaults.DetailedErrorsKey, "true") // and this line
            .UseKestrel()
            .UseStartup<Startup>()
            .Build();

reference: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/hosting?tabs=aspnetcore2x#capture-startup-errors 参考: https : //docs.microsoft.com/zh-cn/aspnet/core/fundamentals/hosting?tabs=aspnetcore2x#capture-startup-errors

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET 4.5在ASP.NET Core 2.0应用程序下的Azure Web App中作为虚拟应用程序抛出502.5 - ASP.NET 4.5 throws 502.5 as a virtual application in Azure Web App under a ASP.NET Core 2.0 application Azure Web App上.NET Core Web API应用程序的动态IP地址限制 - Dynamic IP Address Restrictions for .NET Core Web API Application on azure Web App ASP.NET Core 3 Web应用程序,Azure App Service和ANCM进程内处理程序加载失败 - ASP.NET Core 3 Web Application, Azure App Service, and a ANCM In-Process Handler Load Failure 将ASP.NET Core部署到Azure Web App服务错误 - Deploy ASP.NET Core to Azure Web App Service Error 如何将 .NET Core 3.1 API web 应用程序作为 Z0F4137ED1502B5045426083AA258 服务托管? - How to host a .NET Core 3.1 API web application as windows service? Azure App Servce 的 .Net Core 3.1 Web API 延迟问题 - .Net Core 3.1 Web API latency issue with Azure App Servce Azure Function App Web API 的 .Net Core MSAL 身份验证 - .Net Core MSAL Authentication for Azure Function App Web API 当托管在Azure应用程序服务中时,如何控制添加到ASP.NET核心Web应用程序中的HTTP响应标头? - How can I control the HTTP response headers added to my ASP.NET core web application when hosted in Azure app service? 无法发布 ASP.NET Web API 到 Z3A580F142203677F1FZ3 应用服务 - Cannot publish ASP.NET Web API to Azure App Service 我对作为Azure应用服务(P3)托管的.NET Core 2 Web API的基准RPS有什么期望? - What should my expectation be for baseline RPS for .NET Core 2 web api's hosted as an Azure App Service (P3)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM