I have following route config:
routes.MapRoute(
name: "Downloads",
url: "downloads/{filename}",
defaults: new { controller = "Downloads", action = "Index", filename = UrlParameter.Optional }
);
and following controller code:
public ActionResult Index(string filename)
{ ...
When I call this Action with http://test.com/downloads/test.txt I get a 404. When I call the Action without dots in the filename it works. How can I make MVC pass full filenames to my parameter filename?
This happens probably because if your url contains a dot, IIs handles it as a "physical path" url rather a rewritten one.
One neat way to overcome this is to define a handler for you own scheme, for example :
<system.webServer>
<handlers>
<add name="ApiURIs-ISAPI-Integrated-4.0"
path="/downloads/*"
verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
Thanks @Coder. I added the following code (Dots in URL causes 404 with ASP.NET mvc and IIS) to my web.config and it worked:
<system.webServer>
<handlers>
<add name="ApiURIs-ISAPI-Integrated-4.0" path="/downloads/*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers> ...
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