是否可以从 ASP.Net 中的字符串创建页面?

发布于 2024-07-16 07:42:29 字数 183 浏览 6 评论 0原文

我可以通过以下方式从文件创建页面:

Page page = BuildManager.CreateInstanceFromVirtualPath(
    virtualPath, typeof(Page)) as Page;

如何从流或字符串实例化页面?

谢谢。

I can create a page from a file with:

Page page = BuildManager.CreateInstanceFromVirtualPath(
    virtualPath, typeof(Page)) as Page;

How can I instantiate a page from a stream or a string?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴情换悲伤 2024-07-23 07:42:29

您可以创建自己的 VirtualPathProvider,位于 ASP.NET 解析器和文件系统之间。 ASP.NET 中的默认提供程序从磁盘读取 ASPX 标记,但您可以创建自己的提供程序以从任何位置(SQL、流、字符串等)读取它。

本质上它的工作原理是自定义 VirtualPathProvider 类接管像“~/MyPage.aspx”这样的虚拟路径的处理(您必须将其传递给 BuildManager)。 它提供了自定义逻辑来决定如何处理“~/MyPage.aspx”,其中可能包括返回存储在内存中的字符串或流中的数据。

以下是一些帮助您入门的阅读内容:

You can create your own VirtualPathProvider, which sits between the ASP.NET parser and the file system. The default provider in ASP.NET reads ASPX markup from disk, but you can create your own to read it from anywhere (SQL, a stream, a string, etc).

Essentially how it works is that the custom VirtualPathProvider class takes over the handling of virtual paths like "~/MyPage.aspx" (which you must pass in to the BuildManager). It provides custom logic for deciding what to do with "~/MyPage.aspx", which could include returning data stored in a string or stream in memory.

Here's some reading to get you started:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文