【问题标题】:Getting 'Security Exception' in ASP.Net Web API GET request from a Sub Domain在来自子域的 ASP.Net Web API GET 请求中获取“安全异常”
【发布时间】:2013-12-23 19:45:04
【问题描述】:

我已经在网络上部署了一个测试 asp.net web api 应用程序,但是当我尝试对其进行测试时,它会引发异常。
该应用程序在本地运行。
这是原始 api 链接
http://service.mobinweb.com/api
这是异常详细信息
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed
注意:应用程序部署到子域

这是堆栈跟踪

[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Net.Http.HttpRequestMessageExtensions.GetCorrelationId(HttpRequestMessage request) +0
   System.Web.Http.Tracing.TraceRecord..ctor(HttpRequestMessage request, String category, TraceLevel level) +190
   System.Web.Http.Tracing.SystemDiagnosticsTraceWriter.Trace(HttpRequestMessage request, String category, TraceLevel level, Action`1 traceAction) +102
   System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace) +166
   System.Web.Http.Tracing.Tracers.ContentNegotiatorTracer.Negotiate(Type type, HttpRequestMessage request, IEnumerable`1 formatters) +250
   System.Web.Http.Results.NegotiatedContentResult`1.Execute(HttpStatusCode statusCode, T content, IContentNegotiator contentNegotiator, HttpRequestMessage request, IEnumerable`1 formatters) +76
   System.Net.Http.HttpRequestMessageExtensions.CreateResponse(HttpRequestMessage request, HttpStatusCode statusCode, T value, HttpConfiguration configuration) +111
   System.Net.Http.HttpRequestMessageExtensions.CreateErrorResponse(HttpRequestMessage request, HttpStatusCode statusCode, Func`2 errorCreator) +198
   System.Net.Http.HttpRequestMessageExtensions.CreateErrorResponse(HttpRequestMessage request, HttpStatusCode statusCode, Exception exception) +75
   System.Web.Http.<SendAsync>d__0.MoveNext() +627
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Web.Http.WebHost.<ProcessRequestAsyncCore>d__0.MoveNext() +233
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar) +60
   System.Web.HttpTaskAsyncHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +6
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9628700
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

更新: 本地数据结果json是;

[{"Id":3,"Title":"title goes here","Description":"description goes here","CreatedDate":"2013-12-21T00:00:00","Date":"21/12/2013","OrderBy":1,"NavigateUrl":"www.google.com"}]

【问题讨论】:

  • 堆栈跟踪和一些代码可能会有所帮助,这基本上只表明存在异常,而不是真正可能导致它的原因。
  • @JoachimIsaksson,该网址正在运行。在线查看
  • 您是否尝试访问本地路径? (即 c:\someFolder\someFile)
  • @ThiagoCustodio,我更新了问题,你可以查看本地json数据结果
  • 看起来跟踪是您的问题,请尝试禁用它(在 web.config 或您启用的页面属性中)。

标签: asp.net asp.net-mvc asp.net-web-api


【解决方案1】:

安全异常意味着trust environment 存在问题。

您可以通过在 web.config 中设置以下内容来快速验证这一点。但是当你让 web api 生效时不要使用它。您需要在上线时设置自定义权限集。

<system.web>
    <trust level="Full" originUrl="" />
  </system.web>

【讨论】:

  • 我试过了,但父母级别不允许这样做,我猜是因为托管
  • 我应该在 originUrl="" 中设置什么?像 originUrl="service.mobinweb.com" ?
  • This configuration section cannot be used at this path. This happens when the site administrator has locked access to this section using &lt;location allowOverride="false"&gt; from an inherited configuration file.
  • 它是可选的,只是为了测试不要设置任何东西,它将适用于整个网络应用程序。
  • 你能在web.config中设置以上设置吗?
猜你喜欢
  • 2012-09-14
  • 2012-12-18
  • 1970-01-01
  • 2023-03-09
  • 2015-09-02
  • 2016-06-30
  • 2016-03-12
  • 2013-05-05
  • 1970-01-01
相关资源
最近更新 更多