gpt4 book ai didi

.net - 这两个 ASP.NET MVC IgnoreRoute 指令有什么区别?

转载 作者:行者123 更新时间:2023-12-04 11:29:25 27 4
gpt4 key购买 nike

默认的 ASP.NET MVC 3 项目模板包含以下 IgnoreRoute指示:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

我现在已经看到多个项目将此行(包括 StackExchange's DataExplorer )更改为如下所示:
routes.IgnoreRoute("{*allaxd}", new {allaxd = @".*\.axd(/.*)?"});

任何人都可以解释在什么情况下或一般为什么默认 .axd路由忽略是不够的,而后一个版本呢?或者反过来说,为什么人们会选择不使用后一个版本,而是坚持使用默认版本?

我不得不承认我不完全理解 IgnoreRoute语法,以及 MSDN documentation on the subject很简洁。

最佳答案

Phil Haack 的博客中有解释:Make Routing Ignore Requests For A File Extension

引用 Phil 的话,基本思想是:

One solution to this is to add an appropriate ignore route to indicate that routing should ignore these requests. Unfortunately, we can’t do something like this:


{*path}.aspx/{*pathinfo}

We only allow one catch-all route and it must happen at the end of the URL. However, you can take the following approach....

What I’m doing here is a technique Eilon showed me which is to map all URLs to these routes, but then restrict which routes to ignore via the constraints dictionary. So in this case, these routes will match (and thus ignore) all requests for favicon.ico (no matter which directory) as well as requests for a .aspx file. Since we told routing to ignore these requests, normal ASP.NET processing of these requests will occur.

关于.net - 这两个 ASP.NET MVC IgnoreRoute 指令有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7152602/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com