I maybe expecting too much from ASP.NET, but in Apache it's trivial to rewrite urls so requesting something like: http://mysite/myfolder/mypage/niceurlparameter actually manages to serve static page http://mysite/mypage.html
How do I do that in Global.asax?
I've tried this:
RouteTable.Routes.MapPageRoute("Static HTML", "myfolder/{page}/*", "~/myfolder/{page}.html");
but it keeps returning 404 when i request http://mysite/myfolder/mypage/niceurlparameter.
However, this works:
RouteTable.Routes.MapPageRoute("Static HTML", "myfolder/{page}.html/*", "~/myfolder/{page}.html");
so I do get mypage.html when requesting http://mysite/myfolder/mypage.html/niceurlparameter.
I just want to get rid of ".html" part in my URLs. What am I missing?
UPDATE: For some reason, in former case the '*' wildcard has not been accepted.
Changing to:
RouteTable.Routes.MapPageRoute("Static HTML", "myfolder/{page}/{whatever}", "~/myfolder/{page}.html");
appears to route the request to html page, but then I get the error:
There is no build provider registered for the extension '.html'.
Why in the world it would just work in the former case (with html in URL), and not when html is left out?
We register routes in the Global. asax file and we invoke a RegisterRoutes method in the Application_Start() method. Routing is used to create user friendly URLs. It can also be used to setup the startup page of the application, just like the ASP.NET Web Forms.
In MVC, routing is a process of mapping the browser request to the controller action and return response back. Each MVC application has default routing for the default HomeController. We can set custom routing for newly created controller. The RouteConfig.
Routing is a pattern matching system. Routing maps an incoming request (from the browser) to particular resources (controller & action method). This means routing provides the functionality to define a URL pattern that will handle the request. That is how the application matches a URI to an action.
There is no build provider registered for the extension '.html'
You receive this error because static html files should be handled by the IIS directly. However, in your case the ASP.NET MVC framework is trying to handle the file of type .html
, which it can't.
So if you are think this is what you need to do you will have to make a new provider and register in web.config file. look at this
Custom file extensions for ASP.NET - help needed!
You could simply change your static html content to .aspx files. A simple copy and paste would do the job and it should work fine. It will know how to handle the file type.
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