c# - 从 RDL 调用 Web api 时获取“System.Security.SecurityException”
问题描述
我需要从 SSRS 中托管的报告项目中存在的 RDL 文件调用 Web API。RDL 报告中有一个字段将使用 Web Api 响应。我已经在 RDL 中编写了代码来调用该 api 并使用 System.net 库获取响应,但由于某些 System.Web.permission 错误而失败。
我尝试使用以下用 VB.NET(目标框架版本 2.0)编写的代码来使用 Web api。我也尝试trustlevel = full
在web.config中进行设置,但这不起作用并且仍然出现权限被拒绝错误。我在httpWebRequest
控制台应用程序中使用 ..etc 执行相同的代码时获得了成功的 Web api 响应,但是当我尝试从 RDL 调用时它失败了。请让我知道如何修复 System.net 库权限错误。
调用上述函数以使用 web api 响应时出现以下错误:
System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
代码:
`Public Function STSCall() As String
Dim url As String = "https://httpbin.org/get?token=8041637103881119"
Dim cardNumber As String = String.Empty
Dim httpWebRequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
httpWebRequest.Method = "GET"
httpWebRequest.ContentType = "application/json"
httpWebRequest.Headers.Add("X-AuthMode", "ServerSimpleAuth")
httpWebRequest.Headers.Add("X-ServerAuthKey", "STS")
Dim response = CType(httpWebRequest.GetResponse(), System.Net.HttpWebResponse)
Dim StreamReader As New System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.ASCII)
cardNumber = StreamReader.ToString()
Return cardNumber
End Function`
解决方案
推荐阅读
- python - 使用 Python 和 Paramiko 连接到自定义 SSH 子系统(HP NonStop 上的 TACL 进程)
- java - 如何在注释处理器中访问封闭元素的变量注释?
- android - 使用 Google 登录无法在 Android 上运行(仅在 iOS 上) - Flutter
- xamarin - 当我使用对象属性(get-set)时,Xamarin 表单崩溃的 android 项目
- azure - Azure API 获取一段时间的费用
- javascript - 输出媒体输出到 2 个目录而不是 1 个
- servlets - Java Web 应用程序:无法从 jsp 页面启动 MVC 控制器 (Servlet) 类
- javascript - 函数没有获取值?
- teradata-sql-assistant - Teradata SQL 将单个字符串拆分为表行
- regex - 无法匹配正则表达式中的多个数字