开发者

How to include an external html file in asp.net page

How I can include an external html file in 开发者_JAVA技巧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.


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.


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.


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜