服务器端包含外部 HTML?
在我的 asp.net-mvc 应用程序中,我需要包含一个显示旧页面的页面。 该页面的主体是通过调用现有 Perl 脚本创建的。 此 Perl 脚本是外部托管的。
有没有办法做这样的事情:
<!-- #Include virtual="http://www.example.com/theScript.plx"-->
In my asp.net-mvc application I need to include a page that shows a legacy page.
The body of this page is created by calling an existing Perl script.
This Perl script is externally hosted.
Is there a way to do something like this:
<!-- #Include virtual="http://www.example.com/theScript.plx"-->
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不作为直接包含,因为 ASP.NET 服务器端-includes 要求页面在服务器上编译。
您可以使用 jQuery 在页面加载时从该 URL 下载 HTML,尽管我知道这并不完美。
或者(我不知道这是否有效)您可以执行 WebRequest< /a> 从 ASP.NET MVC 控制器访问 perl 网页,并将生成的 HTML 作为文本放入视图中。这样你就可以利用诸如 之类的东西输出缓存以限制对 perl 页面的点击(如果它不经常更改)。
Not as a direct include, because ASP.NET server-side-includes require the page to be compiled at the server.
You could use jQuery to download the HTML from that URL when the page loads, though I appreciate that's not perfect.
Alternatively (and I have no idea whether this will work) you could perform a WebRequest to the perl webpage from your ASP.NET MVC controller, and put the resulting HTML in the view as text. That way you could make use of things like output caching to limit the hits to the perl page if it doesn't change often.
如果您想一次性完成所有操作,您可以从服务器发出 HTTP 请求并将内容写入页面吗?
像这样的事情:
调用此方法:(
大多数代码公然从 此处 因此未检查)
If you wanted to do it all in one go, you could do an HTTP Request from the server and write the contents to the page?
Something like this:
Calling this method:
(Most code ripped blatantly from here and therefore not checked)
您可以通过简单地使用框架并将框架源设置为需要包含的 url 来以低调的方式实现此目的。这非常简单,无需任何服务器或客户端脚本即可关闭,因此如果可能的话,这将是我的首选方法。
但是,如果您希望 html 显示来自您的服务器,则需要手动包含它 - 通常通过使用
WebRequest
(如 Neil 所说)。不过,您可能希望缓存远程页面以提高性能,因为它是一个 Perl 脚本,我假设该页面是动态的,所以这可能不是一个好主意。You could implement this in a low-key fashion by simply using a frame and setting the frame source to the url that needs to be included. This is quite simple and can be down without any server or client side scripting, so that'd be my preferred approach, if possible.
If you want the html to appear to come from your server, however, you'll need to manually include it - typically by using
WebRequest
as Neil says. You may wish to cache the remote page for performance, though, since it's a perl script, I'll assume the page is dynamic, so this might not be a great idea.