【问题标题】:ASP.NET MVC 3 - DotNetOpenAuth - System.Security.SecurityExceptionASP.NET MVC 3 - DotNetOpenAuth - System.Security.SecurityException
【发布时间】:2011-02-27 22:58:57
【问题描述】:

我正在尝试建立一个使用 DotNetOpenAuth 作为其会员提供商的简单网站。一切都很顺利,直到我遇到以下异常。

[SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
    System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
    System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) +31
    System.Security.CodeAccessPermission.Demand() +46
    System.Net.Configuration.DefaultProxySection.PostDeserialize() +103

代码如下。不幸的是,我无法在本地机器上重现该问题。这是托管在 GoDaddy 共享主机上。导致异常的行是openid.CreateRequest(id):

public virtual ActionResult Authenticate(OpenIdAuthenticationViewModel model, string returnUrl)
{
    OpenIdRelyingParty openid = new OpenIdRelyingParty();
    var response = openid.GetResponse();

    if (response == null)
    {
        Identifier id;
        if (Identifier.TryParse(model.OpenIdUrl, out id))
        {
            try
            {
                var openIdRequest = openid.CreateRequest(id);
                var result = openIdRequest.RedirectingResponse.AsActionResult();
                return result;
            }
            catch (ProtocolException pe)
            {
                ViewData["OpenIdMessage"] = pe.Message;
                return View(model);
            }
        }
        else
        {
            ViewData["OpenIdMessage"] = "Invalid Identifier";
            return View(model);
        }
    }

    // code that handles response
}

我已尝试更改的requirePermission 属性

<section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true" />

但这只会导致异常堆栈跟踪的根不同。在网络上几乎找不到关于这个确切例外的信息。

【问题讨论】:

    标签: asp.net-mvc-3 dotnetopenauth shared-hosting securityexception


    【解决方案1】:

    这看起来是因为您有一个带有以下 sn-p 的 web.config:

    <system.net>
        <defaultProxy enabled="true" />
    </system.net>
    

    尝试删除 &lt;defaultProxy&gt; 标签,这在 GoDaddy 上应该是不必要的。

    【讨论】:

    • 我从 nuget 获得了包,从包描述中它是 3.4.6.10357 版本。我可以给你任何你想要的信息。
    • 太棒了。无论如何,我误读了您问题中的错误消息。我已经更新了我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多