【问题标题】:Can an ASP.NET ASPX Page be Processed From a Source that is not the File System?可以从不是文件系统的源处理 ASP.NET ASPX 页面吗?
【发布时间】:2008-09-30 17:32:45
【问题描述】:

有没有办法执行完整的 ASPX 源文件,其中页面源来自字符串/数据库/资源​​而不是文件系统上的文件?使用 HTTP 处理程序和模块呈现动态内容/图像/等并写入响应是直接的,但似乎没有一种方法可以在文件系统上没有文件的情况下执行/编译 ASPX 源。例如:

  • HttpContext.Current.Server.Execute() 重载需要文件路径
  • System.Web.Compilation.BuildManager 只能从虚拟路径创建

目标是能够从 Handler/Module/ViewEngine 执行如下字符串源,并且不需要文件系统上的文件(但从其他位置获取源):

<%@ Page language="C#" MasterPageFile="~/Shared/Site.Master" Inherits="System.Web.UI.Page" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>ListView Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ListView Example</h3>
<asp:ListView ID="List" runat="server" DataSourceID="ProductDataSource">
<LayoutTemplate><ol><asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder></ol></LayoutTemplate>
<ItemTemplate><li><%# Eval("ProductName") %></li></ItemTemplate>
</asp:ListView>
<asp:AccessDataSource ID="ProductDataSource" runat="server"DataFile="~/App_Data/Northwind.mdb"SelectCommand="SELECT [ProductName], [QuantityPerUnit], [UnitPrice], [CategoryName] FROM [Alphabetical List of Products]"></asp:AccessDataSource>
</form>
</body>
</html>

(注意:上面的示例只是一个简单的示例,但显示了使用服务器控件、数据绑定语法、母版页和页面指令中可能的用户控件声明等...)

我希望这是有道理的!

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    也许您需要virtual path provider。它允许您将 ASPX 和代码隐藏存储在不同的媒体中 - RDBMS、xml 文件等。

    【讨论】:

      【解决方案2】:

      更新:使用 virtualpathprovider 查看korchev 的帖子,更适合这种情况。

      您可以使用带有占位符 literal 控件的虚拟文件并将文字控件替换为实际源吗?

      这些可能没有用,但发布了我发现的几个链接:

      Loading an ASP.NET Page Class dynamically in an HttpHandler

      How To: Dynamically Load A Page For Processing

      【讨论】:

        【解决方案3】:

        我知道 SharePoint Server 曾经将 ASPX 页面保存在数据库中,而不是文件系统中。但是,我不掌握细节。

        【讨论】:

          猜你喜欢
          • 2012-05-15
          • 2013-08-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-12-18
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多