Reputation: 1793
I'm using ASP.NET 3.5 web forms.
I've stored my site path in web.config adding key named "CommonPath".
Now I've one simple html page and want to use this key on this static html page.
So how can i do this? or Is there any other way for this?
Thanks in advance
Upvotes: 0
Views: 10563
Reputation: 40736
What I did in the past was to register ".html" pages to be interpreted as dynamic pages, too. (I.e. just like ASPX).
This can be done through your "web.config" file:
....
<system.web>
<compilation ...>
<buildProviders>
<add extension=".html"
type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
....
and
....
<system.webServer>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated" />
<add name="PageHandlerFactory-Integrated-HTML" path="*.html"
verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory"
resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
....
As Robert points out, this works well with IIS 7 and IIS 7.5 (and probably on above versions, too). If you are using IIS 6, you have to do it through the IIS Management Console.
Upvotes: 2
Reputation: 102783
As per Ramesh and Andrew Barber's comments: the best approach would be to rename the .html file to .aspx, so that ASP.NET will handle it instead of IIS just returning the static file. Add a simple redirect-permanent rule to your web server to handle legacy traffic. If you must leave the .html file as is, you could add a rewrite rule (if you have the IIS Rewrite module installed) to point the .html file to the .aspx file without anyone knowing; or, alternatively, use ASP.NET routing to achieve the same effect.
Upvotes: 1