简体   繁体   English

动态页面创建.aspx

[英]Dynamic Page Creation .aspx

I have a IHttpModule to serve up .aspx page dynamically, this is so I can pack them into a DLL and drop it into an existing web site and serve up my pages. 我有一个IHttpModule来动态提供.aspx页,因此我可以将它们打包到一个DLL中,然后将其放入现有的网站中并提供我的页。

I have a class MyPage derived from System.Web.UI.Page which has a .aspx, .aspx.cs and a aspx.designer.cs file. 我有一个派生自System.Web.UI.Page的类MyPage,该类具有.aspx,.aspx.cs和aspx.designer.cs文件。

When I try to instantiate the class Ie MyPage myNewPage = MyPage(), all of the child controls are null... 当我尝试实例化类Ie MyPage myNewPage = MyPage()时,所有子控件均为null ...

I then attempt to render that page output using Server.Execute(myNewPage) in the BeginRequest event of the IHttpModule. 然后,我尝试在IHttpModule的BeginRequest事件中使用Server.Execute(myNewPage)呈现该页面输出。

I know I can compile the page and use reflector to get the compiled class that's built out, but is there a cleaner way to do this? 我知道我可以编译页面并使用反射器来获取已构建的已编译类,但是有没有更清洁的方法呢?

Or even a better approach to what I'm doing? 甚至是我正在做的更好的方法?

Thanks, Goosey 谢谢,古西

I don't think this is possible. 我认为这是不可能的。 You cannot just instantiate page like any other object. 您不能像其他任何对象一样实例化页面。 What you need "might" be a VirtualPathProvider. 您需要“可能”成为VirtualPathProvider。

I'm not sure it's the best solution, but you can embed all the aspx pages into your dll as assets. 我不确定这是否是最佳解决方案,但是您可以将所有aspx页面作为资产嵌入到dll中。 On request extract the aspx from the embedded resource and write to disk (if it hasn't already happened). 根据要求从嵌入式资源中提取aspx并写入磁盘(如果尚未发生)。

There may be a way to provide the aspx from the embedded resource without actually writing to disk, but I don't know for sure. 可能有一种方法可以从嵌入式资源中提供aspx,而无需实际写入磁盘,但是我不确定。

aspx has some intimate relationship with ASP.NET runtime. aspx与ASP.NET运行时有着密切的关系。 I do not think that instantiating it bu just calling constructor is a good idea. 我认为仅调用构造函数实例化它不是一个好主意。 What you can do instead is to have an empty (standard) aspx and move your code to user controls - ascx 相反,您可以做的是拥有一个空(标准)aspx并将代码移至用户控件-Ascx

Those you can load dynamically using LoadControl method 您可以使用LoadControl方法动态加载的那些

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM