100分求解StrongNameIdentityPermissionAttribute的用法?

junqiang 2003-08-20 01:50:00
参见ms-help://MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconsecuringmethodaccess.htm

我在dll中写了一个类:
[StrongNameIdentityPermissionAttribute(SecurityAction.Demand, PublicKey="...hex...")]
public class Class1
{

}
上面dll有一个sn,且在上面publicKey后也是这个sn的公钥。
我写了一个win程序,且强名也是上面dll的同一个密钥文件,但调用时出错"请求。。。类型权限已失败"。

问题是:我写一个win程序,如何调用这个dll?
想解决的问题是不准别人调用我的dll类库。

...全文
103 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
junqiang 2003-08-22
  • 打赏
  • 举报
回复
to qqchen79(知秋一叶 [MS MVP]) :
还不行呀,出错如下:

未处理的“System.Security.SecurityException”类型的异常出现在 system.windows.forms.dll 中。

其他信息: 请求 System.Security.Permissions.StrongNameIdentityPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 类型的权限已失败。

急,想知道答案。
junqiang 2003-08-22
  • 打赏
  • 举报
回复
to qqchen79(知秋一叶 [MS MVP]):
你的解释很准确,是我测试时失误,我又查了一下msdn,正如你所说。

不愧为ms mvp,我尊敬你。
qqchen79 2003-08-20
  • 打赏
  • 举报
回复
把Demand改成LinkDemand试试看。

对于Windows程序,消息循环(Application.Run)是在System.Windows.Forms.dll里面实现的,所以你的几乎所有代码在运行的时候调用堆栈上面总是有系统的Assembly。
Demand要求调用堆栈上的所有Assembly都满足Permission的要求,在Winform里是做不到的(系统的就不满足)。而LinkDemand只要求直接调用者(你的Windows程序)满足要求。
csharplove 2003-08-20
  • 打赏
  • 举报
回复
UP,大家一起学习
junqiang 2003-08-20
  • 打赏
  • 举报
回复
to qimini(循序渐进) (:
虽不让别人访问,但我要访问呀(安全问题)。
雪狼1234567 2003-08-20
  • 打赏
  • 举报
回复
看看这儿:都有讲解和源码:
http://www.codeproject.com/cs/webservices/wsaltroute2.asp?target=strongnameidentitypermissionattribute
http://www.codeproject.com/cs/webservices/wsaltroute.asp?target=strongnameidentitypermissionattribute
qimini 2003-08-20
  • 打赏
  • 举报
回复
你可以用internal修饰符来定义你的类。这样别的程序集也不可以访问你的DLL。
internal class Class1
{
...your code
}

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧