本文介绍了为什么 w3wp.exe 会通过我的 dotnetcore api 路径查找 web.config?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程序池中单独使用带有部署的 dotnetcore 2.1 或 3.1 Web API 的 IIS 7,我们在查看服务器上的进程监视器时发现,w3wp.exe 工作程序记录了许多错误,他们显然是在寻找 Web.配置.他们检查了 api 路线中的每条路线.预期的行为是 w3wp.exe(一个 IIS 工作程序)会移交"文件.对 dotnetcore 应用程序路由的请求,它将找到端点,但相反,它似乎也在检查 web.config.进程监视器显示 w3wp.exe QueryOpen NAME NOT FOUND 和 PATH NOT FOUND 错误.

我看了几篇文章,得出结论是 web.config 继承有问题,IIS 或 dotnetcore 配置中必须有一些设置指示检查每个 API 路由路径的行为,就好像它是一个虚拟的可能包含新 web.config 的目录文件夹系统.这样做的好处是您可以在子应用程序中使用不同的 web.config,但我们不想要这种好处,我们也不希望这些 IIS 工作人员整天因数以千计的此类错误而炸毁日志.我们找到了一个非常简单的解决方案,IIS 管理员可能会说duh"但希望能救人一段时间.

解决方案

我们在 blog.iis.net 的一篇关于 web.config 继承的旧帖子中找到了答案(

  • 转到 system.applicationHost =>网站 =>虚拟目录默认值

  • 将 allowSubDirConfig 设置为 False

  • 我们还发现 Microsoft 建议您使用此设置在 IIS 上托管 dotnetcore 应用程序

    跳过额外的文件操作可以显着提高具有大量随机数据的网站的性能访问静态内容.

    https:///docs.microsoft.com/en-us/previous-versions//dn529134(v=vs.85)?redirectedfrom=MSDN

    请记住,如果您使用此设置,您需要想出一个解决方案来分隔使用或不使用该设置的应用程序.

    MVC 的相关问题:ASP.NET MVC 安全和 IIS allowSubDirConfig 配置

    Using IIS 7 with a deployed dotnetcore 2.1 or 3.1 web API alone in an application pool, we discovered while looking at Process Monitor on the server, the w3wp.exe workers were logging many errors where they were apparently looking for a web.config. They checked every route in the api's route. The expected behavior was that the w3wp.exe (an IIS worker) would "hand off" the request to the dotnetcore application's routing, which would find the endpoint, but instead, it appeared to be also checking for a web.config. The process monitor revealed w3wp.exe QueryOpen NAME NOT FOUND and PATH NOT FOUND errors.

    I looked at a few articles and concluded it was a problem with web.config inheritance, and there must be some setting in IIS or a dotnetcore configuration that was dictating the behavior of checking each API route path as if it were a virtual directory folder system that might contain a new web.config. The benefit would be that you could have a different web.config in a sub-application, but we didn't want that benefit and we didn't want these IIS workers blowing up the logs with thousands of these errors throughout the day. We found an insanely simple solution that an IIS admin might say "duh" but will hopefully save someone out there some time.

    解决方案

    We found the answer on an old blog.iis.net post about web.config inheritance (https://blogs.iis.net/steveschofield/control-web-config-inheritance-with-iis-7-asp-net-options). There is a configuration called allowsubdirconfig that directs the w3wp.exe worker to check subdirectories for a web.config file. Here's how you change it in IIS applicationhost.config that can be found through IIS Manager:

    1. Go to configuration editor

    2. Go to system.applicationHost => sites => virtual directory defaults

    3. Set allowSubDirConfig to False

    We also discovered that Microsoft recommends you use this setting for hosting dotnetcore applications on IIS

    https://docs.microsoft.com/en-us/previous-versions//dn529134(v=vs.85)?redirectedfrom=MSDN

    Keep in mind, if you use this setting, you'll need to come up with a solution to separate applications that use or don't use the setting.

    Related issue with MVC:ASP.NET MVC security and IIS allowSubDirConfig configuration

    这篇关于为什么 w3wp.exe 会通过我的 dotnetcore api 路径查找 web.config?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-14 05:59