![](/img/trans.png)
[英]CORS support in WebAPI, MVC and IIS with Thinktecture.IdentityModel
[英]Asp.net Webapi CORS with Thinktecture.IdentityModel
我正在研究使用 Thinktecture.Identitymodel 解決 Asp.net Webapi CORS 問題,如該 URL http://brockallen.com/2012/06/28/cors-support-in-webapi-mvc-and-iis-with- thinktecture-身份模型/
我在 .Net 4.5 中使用 VS2012 我在這里遇到了幾個問題:
1)這是我提出請求時遇到的錯誤
試圖以與數組不兼容的類型訪問元素 在執行當前 Web 請求期間發生未處理的異常。 請查看堆棧跟蹤以獲取有關錯誤及其在代碼中的來源的更多信息。 System.ArrayTypeMismatchException: 試圖訪問與數組不兼容的類型的元素。
[ArrayTypeMismatchException: 試圖以與數組不兼容的類型訪問元素。]
System.Collections.Generic.List`1.Insert(Int32 index, T item) +62
Galaxy.CorsConfig.RegisterCors(HttpConfiguration 配置) +99
Galaxy.WebApiApplication.Application_Start() +377[HttpException (0x80004005): 試圖以與數組不兼容的類型訪問元素。]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12864673
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475[HttpException (0x80004005): 試圖以與數組不兼容的類型訪問元素。]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601
我的應用程序池指向 Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.17929
2)我的第二個問題是在完成WebApi中提到的事情之后。 我還需要為 IIS 添加 HTTP 模塊嗎?
它應該很容易開始。 我不知道我在這里缺少什么。 任何指針都受到高度贊賞。
謝謝。
我有一個非常相似的問題,因為 Thinktecture.IdentityModel.Web 1.4 引入了 HttpClient 0.6,它引用了 System.Net.Http* v2.0 程序集,但 MVC 中的 HttpHanders 列表需要 4.0。 一旦我刪除了 Web pkg 及其依賴項,事情就會恢復正常。
我發現我的程序集版本不匹配。 我的實際項目在 .Net 4.0 中,而 Thinktecture 在 .Net 4.5 中。
一旦我確定它起作用了。
與上面 Ben 的解決方案類似,我在使用 Thinktecture.IdentityModel v3.5.0 時出現了這個問題,因為我的 web.config 中引用了舊版本的 System.Net.Http (2.2.13.0) 並安裝在 bin 文件夾中。
從我的 web.config 中刪除dependentAssembly 綁定並刪除舊的 System.Net.Http .dll 解決了這個問題。
這是一個 .NET 4.5 項目。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.