php 如何在asp.net页面中包含外部html文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6938046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:39:16  来源:igfitidea点击:

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

phpasp.nethtml

提问by Able Alias

How I can include an external html filein asp.netweb page. In PHP we can use includefunction, 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 aspxpages.

我如何external html fileasp.net网页中包含一个。在PHP中我们可以使用include函数,如果asp.net有类似的函数,请告诉我。我的意图是,我有一个通用的头 html 文件,所以我需要在所有aspx页面中包含该文件。

回答by Ant Swift

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.

服务器端包含可跨不同平台使用,对于包含静态内容很有用。您可以在 IIS 中使用它们,但我需要在 IIS7 中启用它们。

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

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

有关在 IIS7 中启用 SSI 的说明,请访问http://tech.mikeal.com/

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

对于动态内容,有一种称为 MasterPages 的内置模板方法,应改为使用它。

回答by Mark

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 中执行此操作的最典型方法是使用Master Page。将您的页眉包含在母版页中,并使内容页从中继承。

回答by Dan Diplo

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/tutorialsor 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.

ASP.NET 是与 PHP 不同的框架,因此您最好不要尝试复制您在 PHP 中可能完成的工作方式。我们在 ASP.NET 中使用母版页,而不是对常见元素(例如标题)使用“包含”文件。请参阅http://www.asp.net/master-pages/tutorialsMSDN on Master Pages。母版页(与任何其他 .aspx 页面一样)中的内容可以是静态 HTML 或从控件动态生成的标记。

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 includeselsewhere on SO.

有关更多信息,请参阅问题ASP.NET 等效于服务器端包括SO 上的其他地方。

回答by mim alef

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

除了使用 MasterPage 和UserControl 之外这里提供的一种方法是使用Response.writeFile但是这个解决方案的基本问题是:

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

ASP 不会处理文件中的服务器端脚本。这是因为所有 ASP 代码在包含文件时都已经运行,并且服务器不会再次返回读取任何内容以进行服务器端处理

回答by VoteCoffee

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

您可以通过 IFrames 包含它自 .Net 4.5 起,您可以选择通过

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

有关 IFrame 的更多信息:http: //www.w3.org/html/wg/drafts/html/master/semantics.html#the-if​​rame-element