ASP.NET MVC 3 - DotNetOpenAuth - System.Security.SecurityException

时间:2011-02-27 22:58:57

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

我正在尝试建立一个使用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" />

但这只会导致异常堆栈跟踪的根目录不同。网上有关此确切例外的信息很少。

1 个答案:

答案 0 :(得分:1)

这看起来像是因为你有一个带有以下代码片段的web.config:

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

尝试删除<defaultProxy>标记,无论如何都不需要GoDaddy。