安全异常 - 应用程序尝试执行安全策略不允许的操作
我有一个简单的实现,我实例化 OpenIdRelyingParty,然后调用 RedirectToProvider。它在 1and1 的托管环境以及 Cassini (Visual Studio 2010) 上运行良好。但是,当我将其部署到我的 PC (Windows 7) 上的 IIS 上时,我收到安全异常:
“应用程序试图执行安全策略不允许的操作。要授予此应用程序所需的权限,请联系您的系统管理员或更改配置文件中应用程序的信任级别。”
以下代码中的某处:
protected void Button1_Click(object sender, ImageClickEventArgs e)
{
string realm = WebConfigurationManager.AppSettings["Realm"];
Uri returnPath = new Uri(new Uri(realm), "welcome.aspx");
using (OpenIdRelyingParty openId = new OpenIdRelyingParty())
{
IAuthenticationRequest request = openId.CreateRequest("https://www.google.com/accounts/o8/id",
new DotNetOpenAuth.OpenId.Realm(realm), returnPath);
request.RedirectToProvider();
}
}
错误消息很神秘,有关纠正它的知识库文章更是如此。
- 谁正在尝试执行什么操作?
- DotNetOpenAuth 试图访问什么?
- 谁或什么不信任谁?
- 它所说的安全策略是什么?
- 该政策的内容是什么?
- 我在哪里可以找到它或更改它?
谢谢。
2012 年 5 月 2 日
根据要求,以下是调用堆栈:
[SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) +150
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) +100
System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +283
System.Security.PermissionSetTriple.CheckSetDemand(PermissionSet demandSet, PermissionSet& alteredDemandset, RuntimeMethodHandle rmh) +69
System.Security.PermissionListSet.CheckSetDemand(PermissionSet pset, RuntimeMethodHandle rmh) +150
System.Security.PermissionListSet.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +30
System.Threading.CompressedStack.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +40
System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, CompressedStack securityContext) +123
System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant) +54
I have a simple implementation where I instantiate OpenIdRelyingParty and then call RedirectToProvider. It runs fine in a hosted environment at 1and1 and also on Cassini (Visual Studio 2010). However, when I deploy it onto the IIS on my PC (Windows 7), I get a Security Exception:
"The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file."
somewhere in the following code:
protected void Button1_Click(object sender, ImageClickEventArgs e)
{
string realm = WebConfigurationManager.AppSettings["Realm"];
Uri returnPath = new Uri(new Uri(realm), "welcome.aspx");
using (OpenIdRelyingParty openId = new OpenIdRelyingParty())
{
IAuthenticationRequest request = openId.CreateRequest("https://www.google.com/accounts/o8/id",
new DotNetOpenAuth.OpenId.Realm(realm), returnPath);
request.RedirectToProvider();
}
}
The error message is cryptic and the knowledgebase articles on rectifying it are even more so.
- Who is attempting to perform what operation?
- What is DotNetOpenAuth trying to access?
- Who or what is not trusting who?
- What is the security policy it is talking about?
- What is in that policy?
- Where can I find it or change it?
Thanks.
May 2, 2012
As requested, here is the call stack:
[SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) +150
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) +100
System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +283
System.Security.PermissionSetTriple.CheckSetDemand(PermissionSet demandSet, PermissionSet& alteredDemandset, RuntimeMethodHandle rmh) +69
System.Security.PermissionListSet.CheckSetDemand(PermissionSet pset, RuntimeMethodHandle rmh) +150
System.Security.PermissionListSet.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +30
System.Threading.CompressedStack.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +40
System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, CompressedStack securityContext) +123
System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant) +54
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最有可能的是 OpenID 必须发出的出站 HTTP 请求才能让用户登录。如果您的 web.config 文件将站点设置为在中等信任度下运行,请尝试将其提升为高度信任或完全信任。
中等信任在托管环境中有效但在“在家”中无效的原因是,ASP.NET 附带的默认中等信任配置不允许出站 HTTP 请求,但大多数共享托管环境会修改此设置,以便中等信任允许。
在家里,解决此问题的最简单方法是提高 web.config 文件中的信任级别。
Most likely it's the outbound HTTP request that OpenID must make to log users in. If your web.config file sets up the site to run under medium trust, try bumping it to high or full trust.
The reason medium trust works in hosted environments but not "at home" is because the default medium trust configuration that ships with ASP.NET does not allow outbound HTTP requests, but most shared hosting environments modify this setting so that medium trust allows it.
At home, the easiest way to solve it is to raise the trust level in your web.config file.