1

I want create web application with 2 parameter. Add this Code to RegisterRoutes function:

routes.MapRoute(
               "pageroute",                                              
               "page/{pageid}/{pagename}",                          
               new { controller = "page", action = "Index", pageid = "", pagename = "" } 
           );

and add this method in pageController:

  public ActionResult Index(int pageid,string pagename)
        {
            return View();
        }

Now when i running application with this parameter

http://localhost:1196/page/4/Pagename

Application run successfully but when running with this parameter

http://localhost:1196/page/4/Pagename.html

Application return 404 error

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

while add .html in parameter return 404 error. why?

iman mir
  • 241
  • 1
  • 13
  • 5
    when ulr contains the ".html" then request goes to html pipeline for handling request at iis . You have to force all request through the ASP.NET pipeline. – Sain Pradeep Jun 19 '15 at 12:21
  • agreed with Sain Pradeep – Dinav Ahire Jun 19 '15 at 12:22
  • @SainPradeep How to force to process request with ASP.net? – iman mir Jun 19 '15 at 12:23
  • @dinav Ahrie I use MVC not have .aspx file and page1.html is name of page saved in my database when user call this URL application load page1.html from database and create page and returned to user – iman mir Jun 19 '15 at 12:27
  • pagename is parameter sending to index method of Page controller – iman mir Jun 19 '15 at 12:33
  • 1
    Please refer this http://stackoverflow.com/questions/9331516/asp-net-mvc-routing-add-html-extension-to-routes – Sain Pradeep Jun 19 '15 at 12:33
  • @SainPradeep Thank you i check this link but my problem not resolve – iman mir Jun 19 '15 at 12:44
  • why not just send the name of the page without the extension ? if the extension can be different than '.html' add string extension to the method signature and inside the method, construct your full page name – Mihai Tibrea Jun 19 '15 at 13:30

2 Answers2

1

Because by default HTML files are not being served through MVC/IIS.

Your application looks for a physical file named Pagename.html and cannot find it there. Hence - 404.

To make it work, you need to setup your IIS to catch requests for files with HTML extension and pass this request to MVC.

EDIT: Here is a similar question where OP found a solution by switching "Managed Pipeline Mode" to "Classic".

Community
  • 1
  • 1
anar khalilov
  • 16,993
  • 9
  • 47
  • 62
0

Try changing the Route to:

routes.MapRoute(
           "pageroute",                                              
           "page/{pageid}/{*pagename}",                          
           new { controller = "page", action = "Index", pageid = "", pagename = "" } 
       );

This will then match everything as in page/1/* so the .html should go via this route.

I was unable to reproduce an issue where a .html file gave a 404 using a scenario similar to the question, so there may be some other routing issue or IIS configuration causing this.

freedomn-m
  • 27,664
  • 8
  • 35
  • 57