使用点""字符MVC4路线 [英] Using the dot "." character in MVC4 Routes
问题描述
我目前从这些都是相同的文件类型的数据库中的表提供图片。我想字符点。在路线,但都没有成功这样做。这是我的理解是,ISAPI处理程序可能会导致与此相关的一个问题。我只是不确定我将如何去有关添加和排斥,让眼前这个路线由ASP.NET进行处理。
routes.MapRoute(
名称:的ImageUrl
网址:图像/ {行动} / {ID}巴纽
默认:新{控制器=图片}
);
您获得404错误,因为有映射到路径上没有具体的托管处理程序 PNG *。
在IIS配置。因此,要图像/ *。PNG所有请求
路径由 StaticFile
模块拦截( StaticFileModule, DefaultDocumentModule,DirectoryListingModule
),这些模块找不到请求的文件。
您可以通过在的web.config
配置应用程序解决此问题。
的第一个选项的是 runAllManagedModulesForAllRequests =真正的
属性添加到配置/ system.webServer /模块
元素。应该这样看:
<模块runAllManagedModulesForAllRequests =真/>
注意:但是我会强烈建议不这样做。了解更多关于可能的性能问题的。
所以的第二(和更好的)选项的是注册ASP.NET ISAPI处理您的请求图像/ *。PNG
路径
< system.webServer>
<&处理GT;
<添加名称=ImageMVCHandler-ISAPI-4.0_32bitPATH =图像/ * PNG动词=GET,HEAD模块=IsapiModulescriptProcessor =%WINDIR%\\ Microsoft.NET \\框架\\ v4.0.30319 \\ ASPNET_ISAPI.DLLpreCondition =classicMode,runtimeVersionv4.0,bitness32responseBufferLimit =0/>
<添加名称=ImageMVCHandler-ISAPI-4.0_64bitPATH =图像/ * PNG动词=GET,HEAD模块=IsapiModulescriptProcessor =%WINDIR%\\ Microsoft.NET \\ Framework64 \\ v4.0.30319 \\ ASPNET_ISAPI.DLLpreCondition =classicMode,runtimeVersionv4.0,bitness64responseBufferLimit =0/>
<添加名称=ImageMVCHandler - 集成 - 4.0PATH =图像/ * PNG动词=GET,HEADTYPE =System.Web.Handlers.TransferRequestHandlerpreCondition =integratedMode,runtimeVersionv4.0 />
< /处理器>
< /system.webServer>
I am currently serving images from a database tables which are all of the same file type. I would like the character dot "." in the routes, but have not had any success doing so. It is my understanding that the ISAPI handlers could be causing an issue related to this. I'm just unsure how I would go about adding and exclusion to allow just this route to be handled by ASP.NET.
routes.MapRoute(
name: "ImageUrl",
url: "Image/{action}/{id}.png",
defaults: new { controller = "Image" }
);
You get 404 errors because there is no specific managed handler mapped to path *.png
in IIS configuration. So all requests to Image/*.png
paths are intercepted by StaticFile
modules (StaticFileModule, DefaultDocumentModule, DirectoryListingModule
) and these modules can not find requested files.
You can workaround this problem by configuring your application in web.config
.
The first option is to add runAllManagedModulesForAllRequests="true"
attribute to configuration/system.webServer/modules
element. It should be looking like this:
<modules runAllManagedModulesForAllRequests="true" />
NOTE: But I would strongly recommend to not doing this. Read more about possible performance problems.
So the second (and much better) option is to register ASP.NET ISAPI for handling your requests to Image/*.png
path:
<system.webServer>
<handlers>
<add name="ImageMVCHandler-ISAPI-4.0_32bit" path="image/*.png" verb="GET,HEAD" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ImageMVCHandler-ISAPI-4.0_64bit" path="image/*.png" verb="GET,HEAD" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ImageMVCHandler-Integrated-4.0" path="image/*.png" verb="GET,HEAD" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
这篇关于使用点&QUOT;&QUOT;字符MVC4路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!