2

Is there any way to use ASP or ASP.NET to use an include of a HTML in another HTML file? Similar to the way that you can use an include with PHP with HTML and the AddType handler in .htacess?

I am trying to find a better way to update some navigation but the site sits on a windows server that doesn't have PHP installed on it.

ultraloveninja
  • 1,969
  • 5
  • 27
  • 56
  • Yes, take a look at http://stackoverflow.com/questions/894720/asp-net-equivalent-of-server-side-includes – Alex K. Sep 05 '12 at 15:02

2 Answers2

2

There are a number of options available for you to use the first one I would mention is Master Pages if you going to use asp.net.

ASP.NET MVC uses layouts with the Razor view engine so you can control the page a bit more, I really like the MVC way of doing things as it keeps things simple in terms of your functionality and presentation.

Another option is the server side include (this is old fashioned and not really good):

<!-- #INCLUDE FILE="includeMe.html" -->

If you wanted to keep it as an html page you could 'hack' around in IIS to make html pages work with SSI but it is not a very good way of doing things.

Another way of providing information is by using jQuery to include snippets of html for your page to use, something like this, (sorry I haven't tested):

$("#destination-container").load("sourcepage.htm #content-in-this-page");

Again this is probably not the best way of doing things but you can use it for quick results.

My advice is to create a main page, whether it be a master page or a variation of one if you decide to go the MVC route then use PartialViews or something similar.

And of course look at the link Alex K provided: ASP.NET equivalent of server side includes

Community
  • 1
  • 1
Mr. Mr.
  • 4,257
  • 3
  • 27
  • 42
  • I ended up going the jQuery route. Hacking something together with ASP/ASP.NET was gonna be too much for what I wanted. Plus I don't have complete control over the server so I didn't want to end up breaking something with the rest of the site since ASP.NET is not really in my skill set. I did find this page that helped: http://blog.koostudios.com/?p=127 – ultraloveninja Sep 05 '12 at 16:18
0

If the parent/containing code file has a .asp extension then you can use the following code to include another file.

<!-- #INCLUDE FILE="myfile.htm" -->
Andy Davies
  • 1,456
  • 9
  • 13
  • What if I need to keep it as .html? – ultraloveninja Sep 05 '12 at 15:08
  • Ideally URIs should not reveal implementation details (such as a `.html` file extension), but you can use IIS' URL Rewriting or re-map the `html` file extension to the Classic ASP or SSI module. – Dai Sep 05 '12 at 15:23