I have a web application, which has a user control and web page logic to be used on multiple web applications. The reason I want to do this is that I want the other web applications to reference this one since the html/css of their web pages varies.
我有一个Web应用程序,它具有用户控件和网页逻辑,可用于多个Web应用程序。我想这样做的原因是我希望其他Web应用程序引用这个,因为他们的网页的html / css各不相同。
First of all I wanted to ask if this is possible since it is a web application and not a class library.
首先,我想问这是否可行,因为它是一个Web应用程序而不是类库。
Secondly if it is possible how do I refrence the web page logic to the htmls of the other web applications?
其次,如果有可能我如何将网页逻辑引用到其他Web应用程序的htmls?
2 个解决方案
#1
How about adding the Web User Control to a Class Library and referencing that Class Library from the website ?
如何将Web用户控件添加到类库并从网站引用该类库?
Here are instructions by Haacked on how to add a User Control to a Class Library: http://haacked.com/archive/2006/02/07/AddingWebUserControlToAClassLibraryInVS.NET2005.aspx
以下是Haacked关于如何将用户控件添加到类库的说明:http://haacked.com/archive/2006/02/07/AddingWebUserControlToAClassLibraryInVS.NET2005.aspx
Also here is a post by Guthrie about Building Re-Usable ASP.NET User Control and Page Libraries with VS 2005 and I think it's worth a look.
另外这里是Guthrie关于使用VS 2005构建可重用的ASP.NET用户控件和页面库的帖子,我认为值得一看。
[Update]
I found a better tutorial on Creating and Using User Control Libraries. I think that this article is more concise than the other one by Guthrie (also this one is also by Guthrie)
我找到了一个关于创建和使用用户控制库的更好的教程。我认为这篇文章比Guthrie的另一篇文章更简洁(这也是Guthrie的文章)
#2
Compile and deploy your asp.net website which will produce one assembly per code-behind.
编译和部署你的asp.net网站,每个代码隐藏产生一个程序集。
Pick the assembly of the code-behind class you want to re-use and drop it into the \bin folder of your 2nd web-app in which you want to reuse it.
选择要重复使用的代码隐藏类的程序集,然后将其放入第二个Web应用程序的\ bin文件夹中,以便重用它。
Now this assembly will have a partial class which you can merge with the code-behind of an existing web-page. Just ensure the naming hierarchy are matching.
现在,这个程序集将有一个部分类,您可以将其与现有Web页面的代码隐藏合并。只需确保命名层次结构匹配即可。
#1
How about adding the Web User Control to a Class Library and referencing that Class Library from the website ?
如何将Web用户控件添加到类库并从网站引用该类库?
Here are instructions by Haacked on how to add a User Control to a Class Library: http://haacked.com/archive/2006/02/07/AddingWebUserControlToAClassLibraryInVS.NET2005.aspx
以下是Haacked关于如何将用户控件添加到类库的说明:http://haacked.com/archive/2006/02/07/AddingWebUserControlToAClassLibraryInVS.NET2005.aspx
Also here is a post by Guthrie about Building Re-Usable ASP.NET User Control and Page Libraries with VS 2005 and I think it's worth a look.
另外这里是Guthrie关于使用VS 2005构建可重用的ASP.NET用户控件和页面库的帖子,我认为值得一看。
[Update]
I found a better tutorial on Creating and Using User Control Libraries. I think that this article is more concise than the other one by Guthrie (also this one is also by Guthrie)
我找到了一个关于创建和使用用户控制库的更好的教程。我认为这篇文章比Guthrie的另一篇文章更简洁(这也是Guthrie的文章)
#2
Compile and deploy your asp.net website which will produce one assembly per code-behind.
编译和部署你的asp.net网站,每个代码隐藏产生一个程序集。
Pick the assembly of the code-behind class you want to re-use and drop it into the \bin folder of your 2nd web-app in which you want to reuse it.
选择要重复使用的代码隐藏类的程序集,然后将其放入第二个Web应用程序的\ bin文件夹中,以便重用它。
Now this assembly will have a partial class which you can merge with the code-behind of an existing web-page. Just ensure the naming hierarchy are matching.
现在,这个程序集将有一个部分类,您可以将其与现有Web页面的代码隐藏合并。只需确保命名层次结构匹配即可。