In MVC 3 I didn't have an issue, but now I have gone to MVC 4 I do.
The URL looked like this:
{controller}/{action}/{id}
/podcast/file/PODCAST-01.MP4
Where the PODCAST-01.MP4 is the id; when it hits the controller, the controller would then send the file to the client, it was done this way so that we could easily count how many people downloaded the file.
However, now, the web server, thinks there should be a file there and gives a 404 error. I have tried to get around this by making my own 404 error page and then redirecting back with /podcast/file?id=PODCAST-01.MP4 but this doesn't work because iTunes doesn't like it, it doesn't like the "?".
I tried creating a a new route:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}.{format}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, format = UrlParameter.Optional });
But that seems to have just broken the routing. Any help would be great.
You can do that. In MVC 4 solution web config contains:
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
You simply have to add before those a new handler for you path
<add name="ManagedFileWithExtension" path="podcast/file*" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With