我正在为自己构建一个小型的Twitter网络应用程序。我正在使用TweetSharp,但我一直收到错误:
Server Error in '/test' Application.
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: You cannot use TweetSharp in partial trust without a policy that allows connecting to API endpoints.
The following policy information (or equivalent) must be added to your trust policy:
<IPermission class="System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1">
<ConnectAccess>
<URI uri="http://twitter\.com/.*"/>
<URI uri="http://api.twitter\.com/.*"/>
<URI uri="http://search.twitter\.com/.*"/>
</ConnectAccess>
</IPermission>
Source Error:
[No relevant source lines]
Source File: App_Web_kiqglk9p.1.cs Line: 0
Stack Trace:
[SecurityException: You cannot use TweetSharp in partial trust without a policy that allows connecting to API endpoints.
The following policy information (or equivalent) must be added to your trust policy:
<IPermission class="System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1">
<ConnectAccess>
<URI uri="http://twitter\.com/.*"/>
<URI uri="http://api.twitter\.com/.*"/>
<URI uri="http://search.twitter\.com/.*"/>
</ConnectAccess>
</IPermission>
我已经对这个主题做了一些研究,发现我所要做的就是添加我需要访问我正在使用的.NET Trust Level的URI。所以我转向MEDIUM并改变了:
C:\的Windows \ Microsoft.NET \ Framework64 \ V2.0.50727 \ CONFIG \ web_mediumtrust.config
......就像这样:
ORIGINAL:
<IPermission class="WebPermission" version="1">
<ConnectAccess>
<URI uri="$OriginHost$"/>
</ConnectAccess>
</IPermission>
ALTERED:
<IPermission class="WebPermission" version="1">
<ConnectAccess>
<URI uri="$OriginHost$"/>
<URI uri="http://twitter\.com/.*"/>
<URI uri="http://api.twitter\.com/.*"/>
<URI uri="http://search.twitter\.com/.*"/>
</ConnectAccess>
</IPermission>
但是,我仍然会遇到同样的错误。有任何想法吗?
PS:我不确定这是属于ServerFault还是这里,所以我从这里开始:)
答案 0 :(得分:1)
很抱歉没有及早发现这一点。
有没有理由不能完全信任?我不确定为什么会这样,但你可以提交一个bug。 TweetSharp尝试提前请求WebPermission以避免以后在运行时遇到问题。