我正在尝试建立一个使用 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" />
但这只会导致异常堆栈跟踪的根不同。在网络上几乎找不到关于这个确切例外的信息。