内容文件夹是否在asp.net mvc中是神圣的?

时间:2021-11-07 17:16:20

Is the Content folder special to the underlying framework of MVC? I can't find any reference to it in routing code or configuration.

Content文件夹对MVC的底层框架是特殊的吗?我在路由代码或配置中找不到任何引用。

I'm just wondering if static content can be handled in different ways.

我只是想知道静态内容是否可以用不同的方式处理。

On a related note, *'s script and css content seems to be retrieved by version number in the querystring:

在相关的说明中,*的脚本和css内容似乎是通过查询字符串中的版本号检索的:

<link href="/Content/all.min.css?v=2516" rel="stylesheet" type="text/css" />

Care to speculate how this might work and why this would be important?

注意推测这可能如何起作用以及为什么这很重要?

5 个解决方案

#1


19  

No magic, the System.Web.Routing.RouteCollection class has a property RouteExistingFiles which controls the behavior.

没有魔法,System.Web.Routing.RouteCollection类有一个属性RouteExistingFiles来控制行为。

The default is false, which means ASP Routing should not route the URL, but just return the default content. In this case the "/Content/all.min.css?v=251" skips the MVC routing rules entirely.

默认值为false,这意味着ASP Routing不应路由URL,而只返回默认内容。在这种情况下,“/ Content / all.min.css?v = 251”完全跳​​过MVC路由规则。

if you want to add a routing rule for the content folder, you need to add the rule, and set RouteExistingFiles to true.

如果要为内容文件夹添加路由规则,则需要添加规则,并将RouteExistingFiles设置为true。

#2


5  

No, the Content folder is not sacred. Use it as you like.

不,Content文件夹不是神圣的。随意使用它。

Re the version - that is a common trick to help with versioning if you have http-header based caching enabled; otherwise you can't guarantee that all clients are using the updated files. You'll see a lot of "foo_v4.js" etc on the web ;-p

重新版本 - 如果您启用了基于http头的缓存,这是帮助版本控制的常用技巧;否则您无法保证所有客户端都使用更新的文件。你会在网上看到很多“foo_v4.js”等; -p

#3


4  

I use the same technique on some of my sites. I use it to avoid caching - if you do not specify a different URL for the different builds, clients may have cached the old one.

我在我的一些网站上使用相同的技术。我用它来避免缓存 - 如果你没有为不同的构建指定不同的URL,客户端可能已经缓存了旧的。

#4


3  

Just to add to the other comments about this - the way the routing system works is as follows:

只是添加其他评论 - 路由系统的工作方式如下:

A request comes in, and is directed to the routing engine, which then looks through the route table for a match - in the order they are registered (which is why you should put more specific routes before more general routes).

请求进入,并被引导到路由引擎,路由引擎然后通过路由表查找匹配 - 按照它们注册的顺序(这就是为什么你应该在更一般的路由之前放置更多特定路由)。

If no match is found, the routing engine passes the request on to IIS to handle normally - this is also how you can intermix ASP.NET webforms and MVC in the same application.

如果找不到匹配项,路由引擎会将请求传递给IIS以正常处理 - 这也是您可以在同一应用程序中混用ASP.NET Webforms和MVC的方法。

#5


1  

It has no special meaning. It is just an arbitratry name. If you use the wizard of ASP.NET MVC RC you will find that it is referenced inside your master page (Site.master):

它没有特别的意义。它只是一个仲裁名称。如果您使用ASP.NET MVC RC向导,您会发现它在您的母版页(Site.master)中被引用:

<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />

As to all.min.css used in SO, it could be a custom handler that is executed on the server to retrieve a compressed style sheet by version.

对于在SO中使用的all.min.css,它可以是在服务器上执行的自定义处理程序,以按版本检索压缩样式表。

#1


19  

No magic, the System.Web.Routing.RouteCollection class has a property RouteExistingFiles which controls the behavior.

没有魔法,System.Web.Routing.RouteCollection类有一个属性RouteExistingFiles来控制行为。

The default is false, which means ASP Routing should not route the URL, but just return the default content. In this case the "/Content/all.min.css?v=251" skips the MVC routing rules entirely.

默认值为false,这意味着ASP Routing不应路由URL,而只返回默认内容。在这种情况下,“/ Content / all.min.css?v = 251”完全跳​​过MVC路由规则。

if you want to add a routing rule for the content folder, you need to add the rule, and set RouteExistingFiles to true.

如果要为内容文件夹添加路由规则,则需要添加规则,并将RouteExistingFiles设置为true。

#2


5  

No, the Content folder is not sacred. Use it as you like.

不,Content文件夹不是神圣的。随意使用它。

Re the version - that is a common trick to help with versioning if you have http-header based caching enabled; otherwise you can't guarantee that all clients are using the updated files. You'll see a lot of "foo_v4.js" etc on the web ;-p

重新版本 - 如果您启用了基于http头的缓存,这是帮助版本控制的常用技巧;否则您无法保证所有客户端都使用更新的文件。你会在网上看到很多“foo_v4.js”等; -p

#3


4  

I use the same technique on some of my sites. I use it to avoid caching - if you do not specify a different URL for the different builds, clients may have cached the old one.

我在我的一些网站上使用相同的技术。我用它来避免缓存 - 如果你没有为不同的构建指定不同的URL,客户端可能已经缓存了旧的。

#4


3  

Just to add to the other comments about this - the way the routing system works is as follows:

只是添加其他评论 - 路由系统的工作方式如下:

A request comes in, and is directed to the routing engine, which then looks through the route table for a match - in the order they are registered (which is why you should put more specific routes before more general routes).

请求进入,并被引导到路由引擎,路由引擎然后通过路由表查找匹配 - 按照它们注册的顺序(这就是为什么你应该在更一般的路由之前放置更多特定路由)。

If no match is found, the routing engine passes the request on to IIS to handle normally - this is also how you can intermix ASP.NET webforms and MVC in the same application.

如果找不到匹配项,路由引擎会将请求传递给IIS以正常处理 - 这也是您可以在同一应用程序中混用ASP.NET Webforms和MVC的方法。

#5


1  

It has no special meaning. It is just an arbitratry name. If you use the wizard of ASP.NET MVC RC you will find that it is referenced inside your master page (Site.master):

它没有特别的意义。它只是一个仲裁名称。如果您使用ASP.NET MVC RC向导,您会发现它在您的母版页(Site.master)中被引用:

<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />

As to all.min.css used in SO, it could be a custom handler that is executed on the server to retrieve a compressed style sheet by version.

对于在SO中使用的all.min.css,它可以是在服务器上执行的自定义处理程序,以按版本检索压缩样式表。