I was trying to port a classic ASP site to .net Web Pages, and wondered if it's possible to use .htm file extensions and still have them handled by Razor. The equivalent is a snap in classic ASP, just adding a handler mapping. I consider this to be standard
good practice, because if the website ever needs to be moved to a new platform years in the future, one need not worry about broken bookmarks, lost search engine listings etc. if the pages are always .htm.
I tried the dumb-nuts approach of just adding handler mappings for .htm equivalent to what was there for .cshtml, but the net result is that .htm pages are just served up with source code, not processed. Is there some directive within the pages that would
cause the razor engine to get involved?
My dev environment is 2008 server R2, IIS 7.5, and VWD 2010 Express. I followed the steps indicated to load Web Pages without Webmatrix (installing MVC 3 etc.)
Web Pages (.cshtml and .vbhtml files) are mapped to the WebPageHttpHandler based on their file extensions during PreApplicationStart. You cannot register other extensions after this code has run. There is no API to this event, either, so writing Razor code
in .htm files is not an option that is available to you, I'm afraid.
Is this something that would ever be fixed in a future release of any flavor of asp.net?
Does Microsoft even recognize this as a shortcoming?
It's depressing how an obviously smart feature of the old technology is rubbed out in the new. Everything becomes legacy sooner or later. Why make it hard to handle?
If you think it should be included in the Web Pages framework, you should suggest it at the User Voice site: http://webmatrix.uservoice.com/forums/128313-webmatrix-suggestions.
But I think it's unlikely to be considered because of the different compilation models inherent in classic ASP and ASP.NET.
cbhcmc
Member
34 Points
20 Posts
How to configure a Web Pages site to use .htm file extensions
Jan 01, 2013 03:51 AM|LINK
I was trying to port a classic ASP site to .net Web Pages, and wondered if it's possible to use .htm file extensions and still have them handled by Razor. The equivalent is a snap in classic ASP, just adding a handler mapping. I consider this to be standard good practice, because if the website ever needs to be moved to a new platform years in the future, one need not worry about broken bookmarks, lost search engine listings etc. if the pages are always .htm.
I tried the dumb-nuts approach of just adding handler mappings for .htm equivalent to what was there for .cshtml, but the net result is that .htm pages are just served up with source code, not processed. Is there some directive within the pages that would cause the razor engine to get involved?
My dev environment is 2008 server R2, IIS 7.5, and VWD 2010 Express. I followed the steps indicated to load Web Pages without Webmatrix (installing MVC 3 etc.)
Mikesdotnett...
All-Star
154897 Points
19862 Posts
Moderator
MVP
Re: How to configure a Web Pages site to use .htm file extensions
Jan 01, 2013 08:05 AM|LINK
Web Pages (.cshtml and .vbhtml files) are mapped to the WebPageHttpHandler based on their file extensions during PreApplicationStart. You cannot register other extensions after this code has run. There is no API to this event, either, so writing Razor code in .htm files is not an option that is available to you, I'm afraid.
An easier way of managing legacy URLs in ASP.NET is through URL rewriting: http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
cbhcmc
Member
34 Points
20 Posts
Re: How to configure a Web Pages site to use .htm file extensions
Jan 01, 2013 09:25 AM|LINK
Is this something that would ever be fixed in a future release of any flavor of asp.net?
Does Microsoft even recognize this as a shortcoming?
It's depressing how an obviously smart feature of the old technology is rubbed out in the new. Everything becomes legacy sooner or later. Why make it hard to handle?
Mikesdotnett...
All-Star
154897 Points
19862 Posts
Moderator
MVP
Re: How to configure a Web Pages site to use .htm file extensions
Jan 01, 2013 09:45 AM|LINK
If you think it should be included in the Web Pages framework, you should suggest it at the User Voice site: http://webmatrix.uservoice.com/forums/128313-webmatrix-suggestions. But I think it's unlikely to be considered because of the different compilation models inherent in classic ASP and ASP.NET.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter