将web.config文件放在视图目录中

时间:2021-11-14 20:24:09

I am having the standard issue timeout exception in my production environment whereby, after 90 seconds, the thread will be killed. For the vast majority of my site this isn't a problem.

我在生产环境中遇到标准的问题超时异常,在90秒后,该线程将被终止。对于我的绝大多数网站来说,这不是问题。

However, my sitemap generator is an exception to the rule.

但是,我的站点地图生成器是规则的例外。

Because it relies on the routes created in the application, I have chosen to create it inside the project, as it loads all routes in from the app, and then, effectively uses a customised Html.Action to generate each route.

因为它依赖于在应用程序中创建的路径,所以我选择在项目中创建它,因为它从应用程序加载所有路由,然后,有效地使用自定义的Html.Action生成每个路由。

Because it takes a fair while to create the entire sitemap (5 minutes at last count), I get a YSOD before it has a chance to complete. Now, in webforms, I'd just create a web.config in the directory, and a nice little handler for that page using the location element:

因为创建整个站点地图需要花费很长时间(最后一次计算5分钟),所以在有机会完成之前我会得到一个YSOD。现在,在webforms中,我只是在目录中创建一个web.config,并使用location元素为该页面创建一个漂亮的小处理程序:

<configuration>
  <location path="sitemapgenerator">
    <system.web>
      <httpRuntime executionTimeout="600" /><!-- Ten minutes -->
    </system.web>
  </location>
</configuration>

Without actually creating this config file, I'm convinced that, not only will this not work, but it's also pretty bad practice in MVC anyway, because it then restricts the naming of the sitemap generator to whatever is set in the config file, and not just the routes.

在没有实际创建此配置文件的情况下,我确信这不仅会起作用,而且在MVC中也是非常糟糕的做法,因为它会将站点地图生成器的命名限制为配置文件中设置的任何内容,以及不只是路线。

I could just ensure that the routes and the config file stay up-to-date if I need to change it, but this just seems messy in MVC.

如果我需要更改它,我可以确保路由和配置文件保持最新,但这在MVC中看起来很麻烦。

Can anyone give me any suggestions about this, and whether this web.config method will work out?

任何人都可以给我任何建议,这个web.config方法是否会成功?

Many thanks in advance.

提前谢谢了。

Update: I've done a test on this, and no, it does not work, so I have no fallback solution either. :)

更新:我已经对此进行了测试,不,它不起作用,所以我也没有后备解决方案。 :)

1 个解决方案

#1


Have you tried setting the scriptTimeout property in the initialization of the site map generator?

您是否尝试在站点地图生成器的初始化中设置scriptTimeout属性?

Server.ScriptTimeout = 600;

Server.ScriptTimeout = 600;

#1


Have you tried setting the scriptTimeout property in the initialization of the site map generator?

您是否尝试在站点地图生成器的初始化中设置scriptTimeout属性?

Server.ScriptTimeout = 600;

Server.ScriptTimeout = 600;