4

How I can include an external html file in asp.net web page. In PHP we can use include function, if asp.net have any similar function, please let me know. My intention is, i have a common header html file, so I need to include that file in all aspx pages.

1
  • By "external" you mean HTML files from different domain/website? Commented Aug 4, 2011 at 8:35

5 Answers 5

5

Server side includes are available across different platforms and a useful for including static content. You can use them in IIS but I they need to be enabled in IIS7.

<!-- #include file="Static/Menu.html" -->

Instructions to enable SSI in IIS7 are available at http://tech.mikeal.com/

For dynamic content, there is a built-in method of templating called MasterPages, this should be used instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for actually providing the answer to the question and not answering: you should not do this, do this instead.
3

I'm presuming this is web forms?

The most typical way to do this in asp.net would be to use a Master Page. Include your header in the master page and have the content page inherit from this.

Comments

2

ASP.NET is a different framework to PHP and therefore you are better-off not trying to replicate the way you might have done things in PHP. Instead of using "include" files for common elements, such as a header, we use Master Pages in ASP.NET. Please see http://www.asp.net/master-pages/tutorials or MSDN on Master Pages. The content in a master page (like any other .aspx page) can be static HTML or dynamically generated mark-up from controls.

Another way to have re-usable blocks of content is to create what are called User Controls. These are basically page-fragments that can be reused like other server controls. You can, for instance, create a menu user-control and then embed that in a common master-page. This is a good way of breaking-down your site into manageable "chunks".

For more information see the question ASP.NET equivalent of server side includes elsewhere on SO.

Comments

2

In addition to using MasterPage and UserControl, one way that provided here is that using Response.writeFile but The fundamental problem of this solution is that:

ASP will NOT process server-side script in the file. This is because all the ASP code has already run when it includes the file and the server will not go back to read anything for server-side processing again

1 Comment

Does anyone have the solution for above problem, instead of MasterPage and userControl?
0

you can include it via IFrames Since .Net 4.5, you have the option to include stuff via

More on IFrames: http://www.w3.org/html/wg/drafts/html/master/semantics.html#the-iframe-element

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.