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

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

问题描述

我有一个 .net core web api 应用程序,在本地主机上它在 iis express 和默认 iis 上都运行良好.在我的 Web 服务器上,我想将我的应用程序作为 Asp.Net v4.0 应用程序下的子应用程序托管.我创建了一个子应用程序并部署了我的核心应用程序,然后创建了一个 no managed 应用程序池,并为我的网络核心子应用程序选择了这个应用程序池.我已经完全安装了 .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

<?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=".logsstdout" />
  </system.webServer>
</configuration>

StartUp 类' Configure 方法

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>();
}

程序.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 中未明确定义的任何内容,都会随之而来,并且很可能有一点与 ASP.NET Core 应用程序不兼容.

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天全站免登陆