在IIS上托管Net Core 2.0应用程序会出现内部服务器错误 [英] Hosting net core 2.0 app on iis gives internal server error

查看:234
本文介绍了在IIS上托管Net Core 2.0应用程序会出现内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.net核心Web api应用程序,在localhost上,它在iis express和默认iis上都可以正常工作。在我的Web服务器上,我想将我的应用程序托管为Asp.Net v4.0应用程序下的子应用程序。我创建了一个子应用程序并部署了我的核心应用程序,然后创建了一个无托管应用程序池,并为我的净核心子应用程序选择了该应用程序池。我已经完全安装了.net core 2.0 Windows托管包和.net core 2.0 SDK。

I have a .net core web api application, on localhost it was working fine both on iis express and default iis. On my web server, I want to host my application as a sub-app under a Asp.Net v4.0 application. I have created a sub application and deployed my core app, then created a no managed app pool and chosen this app pool for my net core sub-app. I have fully installed .net core 2.0 windows hosting bundle and .net core 2.0 SDK.

Web.config

Web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\MyApp.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>

StartUp class'配置方法

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger)
{
    logger.AddFile(Configuration.GetValue<string>("LogPath"));
    app.UseDeveloperExceptionPage();
    app.UseDatabaseErrorPage();
    // Enable middleware to serve generated Swagger as a JSON endpoint.
    app.UseSwagger();

    // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
    app.UseSwaggerUI(c =>
    {
        c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyAppV1");
    });


    app.UseMvc();
    //app.UseMiddleware<LoggingMiddleWare>();
}

Program.cs

Program.cs

public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

因此,当我从api调用端点时,它返回500内部服务器错误。

So when I call an endpoint from api, It returns 500 Internal server error.

尽管启用了我的stdoutlog,但没有创建任何日志文件,也看不到任何适当的事件日志。

Despite my stdoutlog is enabled, there is not any log file being created, can not see any proper event logs as well.

推荐答案

这里确实没有足够的答案来回答您的问题,但是基于您将其作为虚拟主机托管的事实在ASP.NET 4应用程序下的应用程序中,最可能的罪魁祸首是Web.config。 Web.config文件由应用程序继承。结果,主应用程序(ASP.NET 4)Web.config中的任何内容(而不是子应用程序(ASP.NET Core应用程序)Web.config中的显式定义)都随处可见,并且很有可能

There's really not enough here to definitively answer your question, but based on the fact that you're hosting it as a virtual application under an ASP.NET 4 app, the most likely culprit is the Web.config. Web.config files are inherited by applications. As a result, anything in your main app (ASP.NET 4) Web.config, not explicitly defined differently in your sub app (ASP.NET Core app) Web.config, comes along for the ride, and there's very likely quite a bit in there that's not compatible with an ASP.NET Core app.

防止这种情况的唯一真实方法是编辑主应用程序的Web.config并显式添加 inheritInChildApplications = false 到几乎每个配置节。必须针对每个部分分别进行此操作;没有全局方法可以禁用继承。

The only real ways to prevent this is to edit the main app's Web.config and explicitly add inheritInChildApplications="false" to pretty much every config section. This has to be done for each section individually; there is no global way to disable inheritance.

不能保证有人不会用某些东西修改父Web.config并忘记将此属性添加到新部分中,所以这也是一个非常脆弱的解决方案。通常,嵌套ASP.NET应用程序不是一个好主意,而嵌套ASP.NET Core应用程序则更糟。我建议您简单地为其提供自己的网站并托管在子域中。这样一来,您遇到的问题就会少得多。

There's no guarantee that someone won't modify the parent Web.config with something and forget to add this attribute to the new section, either, so this is also a very brittle solution. In general, it's a bad idea to nest ASP.NET applications, and it's an even worse idea to nest an ASP.NET Core application. I would suggest simply giving it its own site and hosting on a subdomain. You'll have far less issues that way.

这篇关于在IIS上托管Net Core 2.0应用程序会出现内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆