如何在 Web 用户控件中使用 GAC 中的 dll
其实我的目标是;
- 创建 asp.net Web 服务(命名空间 ws,类 Service1)
- 从 Web 服务创建 dll
- 将此 dll 安装到 GAC
- 创建 ASP.NET Web 应用程序
- 不要在 GAC 中添加对此 dll 的引用
- 创建 Web 用户控件,且背后没有任何代码文件
- 在 Web 用户控件内编写代码以使用 Web 服务 上面创建的(没有参考应用程序)
问题是;
- Web 应用程序是否可以搜索 GAC 内的程序集,即使 程序集未引用应用程序
- 我可以使用此网站吗 用户控件(在这种情况下,UC 将不会被编译,因为它不是 代码隐藏)在其他项目(如 WebParts)中?
PS:我最后的情况: Service1.asmx.cs :
using System.Web.Services;
namespace ws
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
WebUserControl1.ascx :
<%@ Control Language="C#" ClassName="wuc" %>
<script runat="server">
protected override void CreateChildControls()
{
base.CreateChildControls();
ws.Service1 srv = new ws.Service1();
btn.Text = srv.HelloWorld();
}
</script>
<asp:Button runat="server" ID="btn" Text="asdasd" />
Default.aspx :
...
<%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
...
<form id="form1" runat="server">
<div>
<uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
</div>
</form>
...
我编译并网页出现此错误:
Actually my objective is;
- Create asp.net web service (namespace ws, class Service1)
- Create dll from web service
- Install this dll to GAC
- Create ASP.NET web application
- Don't add a reference for this dll in the GAC
- Create Web User Control without any code behind the file
- Write code inside the Web User Control to use the Web Service
created above (without giving reference to application)
The question is;
- Can the web application searchs assembly inside GAC even if the
assembly wasn't referenced to the application - Can I use this web
user control(in this situation UC won't be compiled because it isn't
code behinded) in other projects like WebParts?
PS: My last situation:
Service1.asmx.cs :
using System.Web.Services;
namespace ws
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
WebUserControl1.ascx :
<%@ Control Language="C#" ClassName="wuc" %>
<script runat="server">
protected override void CreateChildControls()
{
base.CreateChildControls();
ws.Service1 srv = new ws.Service1();
btn.Text = srv.HelloWorld();
}
</script>
<asp:Button runat="server" ID="btn" Text="asdasd" />
Default.aspx :
...
<%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
...
<form id="form1" runat="server">
<div>
<uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
</div>
</form>
...
I compiled and web page came up with this error:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Aaaaaaahhhhh!
为什么需要在运行时将程序集安装到 GAC?!这不会有什么好处!
对于您的两个问题的答案是肯定的 - 您可以自己加载程序集,也可以直接使用类似 Assembly.Load 或间接通过(例如)创建一个尝试使用程序集限定类型名称加载类型的页面。
Aaaaaaahhhhhh!
Why do you need to install assemblies to the GAC at runtime?! No good can come of this!
For what its worth the answer to both your questions is yes - you can either load the assembly yourself, either directly using something like Assembly.Load or indirectly by (for example) creating a page which attempts to load a type using an assembly qualified type name.
我已经学习并发布到我的博客。
首先,我们需要从 Web 服务生成 dll:
我们将把 Web 服务的 dll 部署到 GAC。所以我们需要有snk文件。我们将从我们的 cs 创建 dll 文件,但在我们需要创建 snk 之前。
现在我们可以从 cs 文件生成 dll
现在我们可以将此 dll 部署到 GAC
我们可以在 .ascx 文件中的 GAC 中了解 dll 的全名,
我们可以将这些行写入
script runat=server
标记I have learnt and posted to my blog.
First we need to generate dll from webservice:
We will deploy our webservice's dll to GAC. So we need to have snk file. We will create dll file from our cs but before we need to create snk.
Now we can generate dll from cs file
Now we can deploy this dll to GAC
We can learn FullName of our dll in the GAC
in .ascx file we can write these lines inside to
script runat=server
tag