可重用的 ASP.NET 用户控件库:虚拟路径提供程序或 ascx/aspx 副本?

发布于 2024-08-16 07:51:19 字数 459 浏览 5 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挖鼻大婶 2024-08-23 07:51:19

我真的不喜欢斯科特的解决方案。我认为它很丑陋并且会产生不必要的开销。我也看到过类似的行为,但它对我不起作用。

我也有与您描述的相同的要求,并且我使用了虚拟路径提供程序选项。这样我就可以轻松地在 Web 应用程序之间重用所有用户控件,而无需解决问题。

不过,虚拟路径提供程序有几个问题:

  • 如果您的 ascx 文件具有任何导致问题的服务器标记(在 javascript 或任何其他位置),您将收到一个没有多大帮助的运行时错误。
  • 每次更改 ascx 标记或文件本身中存在的 Javascript 时,您都必须重建应用程序才能查看结果。如果您试图更改现有控件的设计,这可能会非常痛苦。

我已经使用了本文中描述的解决方案,效果非常好:

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:

  • If your ascx file has any server tags (in javascript or any other place for that matter) that cause an issue you will get a run time error that is not that helpful.
  • You have to rebuild your application every time you do a change to the ascx's mark up or to Javascript that exists on the file it self in order to see the results. That can be a real pain if you are trying to change the design of an existing control.

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...

ˇ宁静的妩媚 2024-08-23 07:51:19

几周前我遇到了同样的情况,但我无法使斯科特的解决方案发挥作用。我改为使用自定义服务器控件并将它们放入自己的类库中。

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.

梦萦几度 2024-08-23 07:51:19

我真的不认为以这种方式使用用户控件是个好主意。如果您需要将它们放在单独的库中,则应该将它们转换为服务器控件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文