ASP.NET MVC Routing - add .html extension to routes
You're guess that an IIS handler is probably grabbing the request prior to MVC is likely correct.
Assuming IIS 7:
http://technet.microsoft.com/en-us/library/cc770990(v=ws.10).aspx
You need to edit the .html handler in IIS to use ASP.NET.
You can find it in the website properties under the home directory tab in app configuration in the mappings section in II6.
Something along the lines of (version may be different):
C:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll is what you need to handle the .html files.
How to add extension .html in url asp.net mvc 4?
You need to modify Web.config to map requests for your HTML files to TransferRequestHandler.
like so:
<system.webServer>
...
<handlers>
<add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
...
</system.webServer>
This is explained here by Jon Galloway.
And put this to your RouteConfig:
public static void RegisterRoutes(RouteCollection routes)
{
...
routes.MapRoute("Default", "{controller}/{action}.html", new { controller = "Home", action = "Index" });
...
}
Than accessing http://localhost:{port}/Home/Index.html will send you to your Home page.
ASP.NET MVC Route Doesn't Work With .html Extension
I've added HtmlFileHandler to my web.config. And .html routes work now.
<handlers>
<add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
Related Topics
Why Does Binarywriter Prepend Gibberish to the Start of a Stream? How to Avoid It
ASP.NET Button Onclick Event Not Firing
How to Convert String to Integer in C#
How to Detect Which .Net Runtime Is Being Used (Ms VS. Mono)
Is This a Bad Practice to Catch a Non-Specific Exception Such as System.Exception? Why
How Is the Boxing/Unboxing Behavior of Nullable<T> Possible
How to Export a Gridview.Datasource to a Datatable or Dataset
Fill Panel with Gradient in Three Colors
How to Concatenate Two System.Io.Stream Instances into One
Regex: Repeated Capturing Groups
How to Have a Loop in a Windows Service Without Using the Timer
Using a List as a Data Source for Datagridview
Avoiding Null Reference Exceptions
Wpf Combobox: Different Template in Textbox and Drop-Downlist
Get Window State of Another Process
How to Prevent a Single Object Property from Being Converted to a Datetime When It Is a String