3

I have the url: http://localhost:1714/Message/Index

I want to show: http://localhost:1714/Message/Index.html

How can I do it?

3
  • you can do this by writing url rewrite method in .htaccess file iis.net/learn/extensions/url-rewrite-module/… Commented Mar 26, 2015 at 6:57
  • Why do you want to do this? The whole idea of MVC route-mapping is to hide the implementation behind neat URLs. Commented Mar 26, 2015 at 10:51
  • I just wanto to custom the url. i was tired of looking at the URL that does not have the extension. Commented Mar 27, 2015 at 1:35

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.