可重用的 ASP.NET 用户控件库:虚拟路径提供程序或 ascx/aspx 副本?
我有一个 ASP.Net Web 应用程序,我想将其用作其他 Web 应用程序中的可重用用户控件库。
此问题的一种解决方案是使用 Scott Guthrie 此处描述的内容:
http://weblogs.asp.net/scottgu/archive/2005/08/28/423888.aspx,
即在使用控制库。
我实际上看到了另一种解决方案:将 ascx/aspx 嵌入用户控件库中,然后使用自定义虚拟路径提供程序来获取它们。
有谁知道哪种解决方案是最好的?
从部署的角度来看,虚拟路径提供者似乎更好。 然而,“ascx/aspx 复制”解决方案更容易实现(无需创建自定义虚拟路径提供程序)。
I have a ASP.Net web application that I want to use as a reusable user control library in other web applications.
One solution for this problem is to use what Scott Guthrie has described here:
http://weblogs.asp.net/scottgu/archive/2005/08/28/423888.aspx
that is to copy ascx/aspx files (without their code-behind) in the web applications which use the control library.
I actually see another solution: to embed the ascx/aspx in the User control library and then use a custom virtual path provider to get them.
Does anybody know which solution is the best ?
From the deployment point-of-view, the virtual path provider seems to be better.
However the 'ascx/aspx copy' solution is easier to implement (no need to create a custom virtual path provider).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我真的不喜欢斯科特的解决方案。我认为它很丑陋并且会产生不必要的开销。我也看到过类似的行为,但它对我不起作用。
我也有与您描述的相同的要求,并且我使用了虚拟路径提供程序选项。这样我就可以轻松地在 Web 应用程序之间重用所有用户控件,而无需解决问题。
不过,虚拟路径提供程序有几个问题:
我已经使用了本文中描述的解决方案,效果非常好:
http: //www.codeproject.com/KB/user-controls/EmbeddedUserControl.aspx
我希望有所帮助...
I really do not like Scott's solution. I believe it is ungly and creates overhead that is not necessary. I have also seen something similar in action and it just didn't work for me.
I too had the same requirement as you describe and I used the virtual path provider option. This way I could reuse all my user controls between web applications easily and without work arounds.
The virtual path provider has a couple of issues though:
I have used the solution as described in this article and it worked very well:
http://www.codeproject.com/KB/user-controls/EmbeddedUserControl.aspx
I hope that helps...
几周前我遇到了同样的情况,但我无法使斯科特的解决方案发挥作用。我改为使用自定义服务器控件并将它们放入自己的类库中。
I ran into this same situation a few weeks ago and I could not make Scott's solution work. I instead used Custom Server Controls and put those in their own Class Library.
我真的不认为以这种方式使用用户控件是个好主意。如果您需要将它们放在单独的库中,则应该将它们转换为服务器控件。
I really don't think its a good idea to use user controls that way. If you need them in a separate library, you should convert them to server controls.