2012-02-01 53 views
0

允許我有一個簡單的實現方式,其中我實例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 
+0

這個異常的調用堆將非常有幫助。 – 2012-02-02 17:42:11

回答

0

最有可能是出站HTTP請求的OpenID必須登錄用戶如果您的網絡.config文件將站點設置爲在中等信任下運行,嘗試將其顛倒爲高或完全信任。

中等信任在託管環境中工作但不在「在家」的原因是因爲ASP.NET附帶的默認中等信任配置不允許出站HTTP請求,但大多數共享主機環境都會修改此設置,因此中等信任允許它。

在家裏,來解決這個問題最簡單的方法是提高你的web.config文件的信任級別。

+0

它已經滿了。 :( – 2012-05-02 02:41:57

+0

很奇怪,在那之前我還沒有看到過。 – 2012-05-03 14:07:15