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?

8
  • 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. Commented Jun 19, 2015 at 12:21
  • agreed with Sain Pradeep Commented Jun 19, 2015 at 12:22
  • @SainPradeep How to force to process request with ASP.net? Commented Jun 19, 2015 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 Commented Jun 19, 2015 at 12:27
  • 1
    Please refer this stackoverflow.com/questions/9331516/… Commented Jun 19, 2015 at 12:33

2 Answers 2

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".

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

Comments

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.

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.