首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“即时”编译aspx页面

“即时”编译aspx页面
EN

Stack Overflow用户
提问于 2012-11-17 17:24:53
回答 2查看 1K关注 0票数 1

我正在尝试在运行时构建一个aspx页面(通过另一个最终重定向到新页面的aspx页面)。据我所知,必须先预编译aspx页面,然后用户才能查看它们。换句话说,aspx页必须编译为/bin文件夹中的DLL。

在我将我的用户重定向到页面之前,有没有办法告诉IIS,或者通过VB.NET代码对其进行排序,以编译该页面?

任何帮助都会得到极大的重视。

EN

回答 2

Stack Overflow用户

发布于 2013-04-29 10:18:58

您可以使用VirtualPathProvider class从数据库加载页面。

票数 1
EN

Stack Overflow用户

发布于 2012-11-17 18:02:02

基本上,您需要的是动态呈现页面的内容。您可以在服务器端动态创建页面内容,方法是向controls集合添加控件(HTML或server One),例如添加到占位符服务器元素。

例如,您可以使用以下标记创建页面:

代码语言:javascript
复制
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="StackOverflowWebApp.TestPage" %>

<!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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />

    <asp:PlaceHolder runat="server" ID="ContentPlaceHolder"></asp:PlaceHolder>

    </form>
</body>
</html>

然后在代码后台类中,我们可以添加要渲染的控件,这是从数据库中动态读取信息所必需的。

代码语言:javascript
复制
    using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace StackOverflowWebApp
{
    public partial class TestPage : Page
    {
        #region Methods

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            // HERE get configuration from database.

            // HERE create content of the page dynamically.

            // Add reference to css file.
            HtmlLink link = new HtmlLink { Href = "~/Styles/styles.css" };
            link.Attributes.Add("type", "text/css");
            link.Attributes.Add("rel", "stylesheet");
            this.Page.Header.Controls.Add(link);

            // Add inline styles.
            HtmlGenericControl inlineStyle = new HtmlGenericControl("style");
            inlineStyle.InnerText = "hr {color:sienna;} p {margin-left:20px;}";
            this.Page.Header.Controls.Add(inlineStyle);

            // Add div with css class and styles.
            HtmlGenericControl div = new HtmlGenericControl("div");
            this.ContentPlaceHolder.Controls.Add(div);
            div.Attributes.Add("class", "SomeCssClassName");
            div.Attributes.CssStyle.Add(HtmlTextWriterStyle.ZIndex, "1000");

            TextBox textBox = new TextBox { ID = "TestTextBox" };
            div.Controls.Add(textBox);

            // and etc
        }

        #endregion
    }
}

注意:此示例可以作为创建动态页面的起点,动态页面的内容取决于在数据库或配置中指定的值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13429302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档