编译/嵌入ASCX用户控件模板在多个Web应用程序重用 [英] Compiling/Embedding ASCX templated UserControls for reuse in multiple web applications

查看:151
本文介绍了编译/嵌入ASCX用户控件模板在多个Web应用程序重用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是到一个真正的摸不到头脑这里...,这似乎是ASP.NET的更令人沮丧的话题之一。

I'm onto a real head scratcher here ... and it appears to be one of the more frustrating topics of ASP.NET.

我有一个实现批量定制LINQ的东西,这在它的核心具有零Web功能的组件。我有一个扩展此组件与网络特定行为的附加组件。

I've got an assembly that implements a-lot of custom Linq stuff, which at it's core has zero web functionality. I have an additional assembly that extends this assembly with web specific behaviour.

该网站的特定行为带有标记的ASCX用户控件模板内的一对夫妇的用户控件。

The web specific behaviour comes with a couple of user controls marked up inside ASCX templated UserControls.

我无法把一个很好的完成对本次大会,以便它是简单的重新部署在其他应用程序中使用。让我通过什么我试过到目前为止运行:

I'm having trouble putting a nice finish on this assembly so that it is simple to redeploy for use in other applications. Let me run through what I've tried so far:


  1. 的ASCX文件复制到使用生成事件消费Web应用程序;的很不理想,相当部署噩梦的。

  2. 实现了自定义的VirtualPathProvider和装配为嵌入的资源范围内嵌入ASCX模板。不幸的是在消费应用中使用Register指令时,它会创建名牌声明为用户控件,在这里我将要求实际控制类型的声明;的不可预见的(典型值)和不良

  3. 创建了一个Web部署项目编译用户控件,但编译的用户控件,接着成为另一个组件的一部分,并从类的定义在我的web组件不再下降 - 的组装需要实例他们依赖请求上下文

  1. Copied the ASCX files to the consuming web application using build events; far from ideal and quite a deployment nightmare.
  2. Implemented a custom VirtualPathProvider and embedded the ASCX templates within the assembly as embedded resources. Unfortunately when using the Register directive in the consuming application it creates the designer declaration as a UserControl, where I would require a declaration of the actual control type; unforeseen (typically) and undesirable.
  3. Created a Web Deployment Project to compile the UserControls, but the compiled user controls then become part of another assembly, and no longer descend from the class definitions in my web assembly--the assembly needs to instantiate them dependent on the request context.

所以1号仅仅是废话,2号不给我的类型支持我的愿望和3号我想我将要产生一个合理的解决方案有:

So number 1 is just crap, number 2 doesn't give me the type support I desire and number 3 I think I'm about to produce a reasonable solution with:


  • 把所有非控制类到 APP_ code 文件夹,prepare一个工厂类,将使用反射构造所需的控制类型的对象并且该类型被反射的期望将在部署输出(希望由类名属性的presence在<$ C $保证present C>控制指令)。

  • Lump all non-control classes into the App_Code folder, prepare a factory class that will construct an object of the desired control type using reflection and the expectation that the type being reflected will be present in the deployment output (hopefully guaranteed by the presence of the ClassName attribute in the Control directive).

也Theres总是重写ASCX控制到自定义控制的其他选项,但只是苦于没有足够的时间来考虑它的资源,我们有没有专业知识,这样做,他们做工精细的用户控件

Theres also always the other option of rewriting the ASCX controls into custom controls, but just don't have the resources to consider it at the moment, and we've got no expertise in doing that, and they work fine as UserControls.

我失去了一些东西很明显,也许事情简单得多,或者这只是故意难吗?我读过的ASP.NET编译过程是非常不幸的,在它的上我的旅行设计过这个话题的故事。

Am I missing something obvious, something maybe much simpler, or is this just purposefully difficult? I've read stories of the ASP.NET compilation process being very unfortunate in it's design on my travels across this topic.

推荐答案

嗯,我想我已经做到了......只要注意几个几个烦人的陷阱与我的最后一个方法,我提出以下建议编译时在使用Web部署项目Web应用程序项目ASCX用户控件:

Well I think I've done it ... by being mindful of a few of a few annoying pitfalls with my last approach, I recommend the following when compiling ASCX user controls in a Web Application Project using a Web Deployment Project:


  1. 避免将类 APP_ code ,除非他们是独立或辅助类,ASP.NET把这个作为的 speshul 的文件夹,它的意思是失去了我,混乱,困惑和混乱如下。此文件夹中code确实得到了Web部署项目输出,虽然。

  2. 密切关注你的程序集名称,它们的根命名空间和部署输出装配的名字 - 你会得到访问被拒绝错误,如果您有任何期间命名冲突的 aspnet_merge 的过程。

  3. 最终你将最有可能最终会部署2集,我想只有一个创造,但部署输出仍指向源组件类型定义。这不是一个问题,如果你没有任何其他类型的Web应用程序项目 - 我有,所以它是我的问题。就我而言,我的最终输出是:

    • &LT;组织&GT;&LT; TechnologyName&GT; .Web.DLL - 编译Web应用程序组件(含ASCX模板)

    • &LT;组织&GT;&LT; TechnologyName方式&gt; .Web.UI.DLL - ASP.NET编译用户控件组件,通过Web部署项目创建

  1. Avoid putting classes in App_Code unless they're standalone or helper classes, ASP.NET treats this as a speshul folder, the meaning of which is lost on me, mayhem, confusion and chaos follows. Code in this folder does get output in the Web Deployment Project, though.
  2. Pay close attention to your assembly names, their root namespaces and deployment output assembly name- you'll get access is denied errors if you have any naming conflicts during the aspnet_merge process.
  3. Ultimately you'll most likely end up deploying 2 assemblies, I tried to create only one but the deployment output was still pointing to type definitions in the source assembly. This isn't a problem if you don't have any other types in your Web Application Project--I have so it was a problem for me. In my case, my final output was:
    • <Organisation>.<TechnologyName>.Web.DLL - Compiled Web Application Assembly (containing the ASCX templates)
    • <Organisation>.<TechnologyName>.Web.UI.DLL - ASP.NET Compiled UserControl assembly, created by Web Deployment Project

有一些耐心备用,这是相当棘手!但是,你在它的结束得到一些不错的重新分配的用户控件!

Have some patience spare, it's quite tricky! But you do get some nice re distributable UserControls at the end of it!

唷!

这篇关于编译/嵌入ASCX用户控件模板在多个Web应用程序重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆