我可以将 Web UserControl ascx 和代码存储在数据库中并从那里加载吗?
有什么方法可以将 UserControl 的代码存储在数据库表中,动态编译它或从那里加载它?意味着我从数据库中获取一个包含 UserControl 完整代码的字符串,然后将其添加到页面中?
Is there any way I can store the code of the UserControl in a database table, compile it dynamically or Load it from there ? Means I get a string from database that contains the complete code of UserControl and then add it to the page ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些想法:
选项 1:临时文件(最简单)
~/tmp/
(并给出Web 应用程序修改和创建该目录的权限)将 UserControl 内容保存到临时文件:
加载用户控件:
将用户控件添加到所需页面:
选项 2:HttpHandler
响应
流然后按照选项 1 加载控件:
id=NNN
发生变化)。 URL 重写可能会解决这个问题。选项 3:编译页面而不仅仅是控件:
BuildManager.CreateInstanceFromVirtualPath()
编译Page< /code> 在 ASP.NET 中来自虚拟路径。因此,您可以将整个页面存储在数据库中并动态编译它。
免责声明:我不建议在数据库中存储控件或页面;它将增加维护、调试和安全成本。
A few ideas:
Option 1: temp files (easiest)
~/tmp/
(and give the web application modify & create permissions to that directory)Save the UserControl contents to a temp file:
Load the user control:
Add the user control to the desired page:
Option 2: HttpHandler
Response
streamThen load the control as in Option 1:
id=NNN
changes). URL rewriting might work around this.Option 3: Compiling pages instead of just controls:
BuildManager.CreateInstanceFromVirtualPath()
compiles aPage
in ASP.NET from a virtual path. So you could store an entire page in the database and compile it dynamically.Disclaimer: I don't recommend storing controls or pages in the database; it will increase maintenance, debugging, and security costs.