我正在silverlight 中开发一个Web 应用程序。我已经重载了 WebClient.GetWebRequest 方法,如下所示:-
public class WebClientWithCookies : WebClient
{
[SecurityCritical]
protected override WebRequest GetWebRequest(Uri address)
{
string cookieContent = HtmlPage.Document.Cookies;
WebRequest request = base.GetWebRequest(address);
HttpWebRequest webRequest = request as HttpWebRequest;
if (webRequest != null && cookieContent != null && cookieContent != string.Empty)
{
CookieContainer cookieContainer = new CookieContainer();
cookieContainer.Add(address, new Cookie() { Value = HtmlPage.Document.Cookies });
webRequest.CookieContainer = cookieContainer;
}
return request;
}
}
但我收到以下异常:
System.TypeInitializationException 未被用户代码处理
Message='SigmaWC.Utility.RestCommunicator' 的类型初始化程序引发了异常。TypeName=SigmaWC.Utility.RestCommunicator
StackTrace:在 SigmaWC.Utility.RestCommunicator..ctor() 在 SigmaWC.App..ctor() InnerException:System.TypeLoadException 消息=在覆盖成员时违反了继承安全规则:'SigmaWC.Utility.WebClientWithCookies ..ctor()'。重写方法的安全可访问性必须与被重写方法的安全可访问性相匹配。StackTrace:在 SigmaWC.Utility.RestCommunicator..cctor() InnerException:
任何人都可以帮助如何提升 Silverlight 中的安全设置。