我正在嘗試在Visual Studio 2012中設置Web應用程序項目,這是我的老闆給我的設置。如何在Visual Studio中正確設置項目
當我在VS通過.sln
文件打開項目它給了我以下錯誤:
The imported project "..\.nuget\nuget.targets" was not found. Confirm that path in the ,<Import> declaration is correct and that the file exist on disk.
所以我發現SO溶液中取出,以下線形態.csproj
文件:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
並重新加載項目這次它正確打開,但是當我建立該項目時,它給了以下錯誤:
Assembly 'System.Web.Http.Cors, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
,這是packages.config
文件:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="3.1.0" targetFramework="net45" />
<package id="EntityFramework" version="6.0.0-beta1" targetFramework="net45" />
<package id="Microsoft.AspNet.Cors" version="5.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.1" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi" version="4.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Cors" version="5.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="2.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages.Data" version="2.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages.WebData" version="2.0.30506.0" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Mvc4Futures" version="4.0.20710.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="5.0.6" targetFramework="net45" />
</packages>
我然後從包管理器控制檯安裝Microsoft.AspNet.WebApi 4.0.30506.0
和Microsoft.AspNet.WebApi.Cors 5.0.0-beta2
。現在
該項目成功地建立,但是當我在執行項目時,我收到以下錯誤:
Attempt by security transparent method 'System.Web.Http.Cors.EnableCorsAttribute..ctor(System.String, System.String, System.String, System.String)' to access security critical method 'System.Web.Cors.CorsPolicy..ctor()' failed.
Assembly 'System.Web.Http.Cors, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.
在這一行:
var cors = new EnableCorsAttribute("*", "*", "*");
請指引我。
Thanx。
但我想打開一個已經創建的項目,而不是試圖創建新的項目。 – user2517610
@ user2517610關注此鏈接http://stackoverflow.com/questions/18347290/webapi-odata-5-0-beta-accessing-globalconfiguration-throws-security-error –