Using period "." character in MVC4 routes

I am currently browsing images from database tables that have the same file type. I would like the dot character "." in the routes, but did not succeed. As I understand it, ISAPI handlers can cause a problem with this. I just don’t know how I will add and exclude to allow this route only ASP.NET.

routes.MapRoute( name: "ImageUrl", url: "Image/{action}/{id}.png", defaults: new { controller = "Image" } ); 
+4
source share
1 answer

You get 404 errors because the IIS configuration does not have a specific managed handler mapped to the *.png path. Thus, all requests to the Image/*.png StaticFile intercepted by the StaticFile modules ( StaticFileModule, DefaultDocumentModule, DirectoryListingModule ), and these modules cannot find the requested files.

You can solve this problem by configuring the application in web.config .

The first option is to add the runAllManagedModulesForAllRequests="true" attribute to the configuration/system.webServer/modules element. It should look like this:

  <modules runAllManagedModulesForAllRequests="true" /> 

NOTE: But I highly recommend not to do this. Learn more about potential performance issues .

So, the second (and much better) option is to register ASP.NET ISAPI to process your requests on the 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> 
+2
source

All Articles