0

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

Arvind S Salunke
  • 1,783
  • 3
  • 15
  • 14
  • 1
    Can't you change the static page to dyanamic page? – Ramesh Apr 12 '12 at 06:02
  • 3
    So, you are using the wrong tool for the job, and asking us how to fix it? If you need dynamic content, you need to use a file type that can produce dynamic content. You can use routing to 'fake' the form. – Andrew Barber Apr 12 '12 at 06:12
  • You can add a IFRAME in your HTML file and point to a ASPX page, which pull the web.config setting. – Deepu Madhusoodanan Apr 12 '12 at 06:31

2 Answers2

2

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.

Community
  • 1
  • 1
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • You forgot to mention that this only works (this way) on IIS 7+. On IIS 6 one has to add add a new ISAPI filter to accomplish the same task. – Robert Koritnik Apr 12 '12 at 06:42
1

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.

McGarnagle
  • 101,349
  • 31
  • 229
  • 260