我有一个简单的实现,我实例化OpenIdRelyingParty然后调用RedirectToProvider。它在1and1和Cassini(Visual Studio 2010)的托管环境中运行良好。但是,当我将其部署到我的PC上的IIS(Windows 7)时,我得到一个安全例外:
“应用程序尝试执行安全策略不允许的操作。要授予此应用程序所需的权限,请与系统管理员联系或更改配置文件中应用程序的信任级别。”
以下代码中的某处:
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();
}
}
错误信息含糊不清,关于纠正它的知识库文章更是如此。
感谢。
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
答案 0 :(得分:0)
很可能是OpenID必须用来登录用户的出站HTTP请求。如果您的web.config文件将站点设置为在中等信任下运行,请尝试将其提升为高信任或完全信任。
介质信任在托管环境中工作但不在“在家”的原因是因为ASP.NET附带的默认介质信任配置不允许出站HTTP请求,但大多数共享托管环境修改此设置以便中等信任允许它
在家里,最简单的解决方法是提高web.config文件中的信任级别。