尝试使用安全透明方法'Microsoft.Web.Helpers.PreApplicationStartCode.Start()'来访问安全关键方法

时间:2014-02-16 22:05:30

标签: c# asp.net asp.net-mvc nuget-package

我的解决方案中有两个MVC网站,转换为MVC5。对于特定测试,我需要两个站点都在运行,因为一个站点通过Web API与另一个站点进行通信。他们正在使用IIS Express运行。

当我在Visual Studio(2012)中启动其中一个并访问已启动的一个时,一切正常。当我尝试访问另一个时,我有以下消息:

  

尝试使用安全透明方法'Microsoft.Web.Helpers.PreApplicationStartCode.Start()'来访问安全关键方法'System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)'失败。

正如其他答案所示,我更新了我的所有软件包,并从其中一个软件包中卸载了DotNetOpenAuth个软件包,没有结果。

这是网站#1的package.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AntiXSS" version="4.2.1" targetFramework="net45" />
  <package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
  <package id="BeginCollectionItem" version="1.2.1.0" targetFramework="net45" />
  <package id="Code52.i18n.MVC4" version="0.2.8" targetFramework="net45" />
  <package id="CSS-Filters-Polyfill" version="1.0.0" targetFramework="net45" />
  <package id="DotNet.Highcharts" version="2.0" targetFramework="net45" />
  <package id="DotNetOpenAuth.AspNet" version="4.3.4.13329" targetFramework="net45" />
  <package id="DotNetOpenAuth.Core" version="4.3.4.13329" targetFramework="net45" />
  <package id="DotNetOpenAuth.OAuth.Consumer" version="4.3.4.13329" targetFramework="net45" />
  <package id="DotNetOpenAuth.OAuth.Core" version="4.3.4.13329" targetFramework="net45" />
  <package id="DotNetOpenAuth.OpenId.Core" version="4.3.4.13329" targetFramework="net45" />
  <package id="DotNetOpenAuth.OpenId.RelyingParty" version="4.3.4.13329" targetFramework="net45" />
  <package id="EntityFramework" version="6.0.1" targetFramework="net45" />
  <package id="Facebook" version="6.4.2" targetFramework="net45" />
  <package id="Faker" version="1.2" targetFramework="net45" />
  <package id="Faker.Net" version="1.0.3" targetFramework="net45" />
  <package id="Galleria.js" version="1.2.9" targetFramework="net45" />
  <package id="HtmlAgilityPack" version="1.4.6" targetFramework="net45" />
  <package id="ImageResizer" version="3.3.3" targetFramework="net45" />
  <package id="iTextSharp" version="4.1.2" targetFramework="net45" />
  <package id="jQuery" version="1.10.2" targetFramework="net45" />
  <package id="jQuery.Cookie" version="1.3.1" targetFramework="net45" />
  <package id="jQuery.MaskedInput" version="1.3.1.1" targetFramework="net45" />
  <package id="jQuery.UI.Combined" version="1.10.3" targetFramework="net45" />
  <package id="jQuery.Validation" version="1.8.1" targetFramework="net45" />
  <package id="jquery-globalize" version="0.1.3" targetFramework="net45" />
  <package id="knockoutjs" version="2.2.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Mvc" version="5.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Providers" version="1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Providers.Core" version="1.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.Razor" version="3.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi" version="5.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebHelpers" version="3.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages" version="3.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages.Data" version="3.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages.OAuth" version="3.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages.WebData" version="3.1.1" targetFramework="net45" />
  <package id="Microsoft.Bcl" version="1.1.6" targetFramework="net45" />
  <package id="Microsoft.Bcl.Build" version="1.0.13" targetFramework="net45" />
  <package id="Microsoft.jQuery.Unobtrusive.Ajax" version="2.0.30506.0" targetFramework="net45" />
  <package id="Microsoft.jQuery.Unobtrusive.Validation" version="2.0.30506.0" targetFramework="net45" />
  <package id="Microsoft.Net.Http" version="2.2.18" targetFramework="net45" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
  <package id="ModelMetadataExtensionsWithBugfix" version="0.1.2" targetFramework="net45" />
  <package id="Modernizr" version="2.6.2" targetFramework="net45" />
  <package id="Moq" version="4.0.10827" targetFramework="net45" />
  <package id="morelinq" version="1.0.16006" targetFramework="net45" />
  <package id="MvcMailer" version="4.5" targetFramework="net45" />
  <package id="MvcScaffolding" version="1.0.9" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="5.0.8" targetFramework="net45" />
  <package id="PagedList" version="1.16.0.0" targetFramework="net45" />
  <package id="PagedList.Mvc" version="4.3.0.0" targetFramework="net45" />
  <package id="RazorGenerator.Mvc" version="2.1.1" targetFramework="net45" />
  <package id="RazorGenerator.Testing" version="2.1.1" targetFramework="net45" />
  <package id="RazorPDF" version="1.0.0" targetFramework="net45" />
  <package id="ReflectionMagic" version="2.0.0" targetFramework="net45" />
  <package id="RestSharp" version="104.1" targetFramework="net45" />
  <package id="SendGrid" version="1.1.1" targetFramework="net45" />
  <package id="System.Management.Automation" version="6.1.7601.17515" targetFramework="net45" />
  <package id="System.Web.Providers" version="1.2" targetFramework="net45" />
  <package id="T4Scaffolding" version="1.0.8" targetFramework="net45" />
  <package id="T4Scaffolding.Core" version="1.0.0" targetFramework="net45" />
  <package id="WebActivator" version="1.5.3" targetFramework="net45" />
  <package id="WebActivatorEx" version="2.0.4" targetFramework="net45" />
  <package id="WebGrease" version="1.6.0" targetFramework="net45" />
</packages>

网站#2上的packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
  <package id="BeginCollectionItem" version="1.2.1.0" targetFramework="net45" />
  <package id="CSS-Filters-Polyfill" version="1.0.0" targetFramework="net45" />
  <package id="EntityFramework" version="6.0.1" targetFramework="net45" />
  <package id="Facebook" version="6.1.4" targetFramework="net45" />
  <package id="ImageResizer" version="3.4.2" targetFramework="net45" />
  <package id="jQuery" version="1.9.1" targetFramework="net45" />
  <package id="jQuery.MaskedInput" version="1.3.1.1" targetFramework="net45" />
  <package id="jQuery.UI.Combined" version="1.10.3" targetFramework="net45" />
  <package id="jQuery.Validation" version="1.9.0.1" targetFramework="net45" />
  <package id="jQuery-Timepicker-Addon" version="1.0.0" targetFramework="net45" />
  <package id="knockoutjs" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.Mvc" version="5.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Mvc.Facebook" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.Razor" version="3.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi" version="5.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.HelpPage" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.OData" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.SelfHost" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Tracing" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebHelpers" version="3.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages" version="3.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages.Data" version="3.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages.WebData" version="3.1.1" targetFramework="net45" />
  <package id="Microsoft.Bcl" version="1.1.6" targetFramework="net45" />
  <package id="Microsoft.Bcl.Build" version="1.0.13" targetFramework="net45" />
  <package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net45" />
  <package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net45" />
  <package id="Microsoft.jQuery.Unobtrusive.Ajax" version="2.0.20710.0" targetFramework="net45" />
  <package id="Microsoft.jQuery.Unobtrusive.Validation" version="2.0.20710.0" targetFramework="net45" />
  <package id="Microsoft.Net.Http" version="2.2.18" targetFramework="net45" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
  <package id="Modernizr" version="2.5.3" targetFramework="net45" />
  <package id="MvcFlash.Core" version="2.0.1" targetFramework="net45" />
  <package id="MvcScaffolding" version="1.0.9" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="5.0.8" targetFramework="net45" />
  <package id="System.Spatial" version="5.6.0" targetFramework="net45" />
  <package id="T4Scaffolding" version="1.0.8" targetFramework="net45" />
  <package id="T4Scaffolding.Core" version="1.0.0" targetFramework="net45" />
  <package id="Twitter.Bootstrap" version="3.0.0" targetFramework="net45" />
  <package id="Twitter.Bootstrap.MVC" version="2.0.0" targetFramework="net45" />
  <package id="WebActivatorEx" version="2.0.4" targetFramework="net45" />
  <package id="WebGrease" version="1.6.0" targetFramework="net45" />
  <package id="XmlExport" version="0.3.2" targetFramework="net45" />
  <package id="XmlOutput" version="1.0.0" targetFramework="net45" />
</packages>

我还能尝试什么?

修改

Web API调用(一个站点调用另一个站点):

if (SettingsHelper.GetCurrentSettings().IntegratedToFederated)
{
    // Report Federated
    var pointsGranted = new APIPointsGrantedModel();
    pointsGranted.CustomerId = customerPointsPerShop.Customer.ControlKey;
    pointsGranted.ShopId = (Guid)customerPointsPerShop.Shop.ControlKey;
    pointsGranted.Amount = customerPointsPerShop.Points;
    pointsGranted.Timestamp = DateTime.Now;

    HttpClient aClient = new HttpClient();
    var website = context.Settings.FirstOrDefault().FederatedWebsite;
    Uri theUri = new Uri(website + "/api/APIShops/PointsGranted");
    HttpResponseMessage aResponse = await aClient.PostAsync(theUri, StringContentHelper.BuildStringContent(pointsGranted, pointsGranted.GetType()));

    if (aResponse.IsSuccessStatusCode)
    {
        var responseContent = await aResponse.Content.ReadAsAsync<APIPointsGrantedModel>();
        // Read the response and perform some business logic
    }
    else
    {
        String failureMsg = "HTTP Status: " + aResponse.StatusCode.ToString() + " - Reason: " + aResponse.ReasonPhrase;
        this.FlashError(failureMsg);
        // TODO: Register in log.
    }
}
站点#1的

web.config

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  ...
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.4.13329" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.4.13329" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebMatrix.WebData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.1402.2112" newVersion="4.2.1402.2112" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="itextsharp" publicKeyToken="8354ae6d2174ddca" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="4.1.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
    </assemblyBinding>
    ...
</configuration>
站点#2的

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  ...
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <!-- dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly -->
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebMatrix.WebData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <!-- dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.OpenId" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly -->
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <!-- dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.OAuth.Consumer" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.OAuth" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.OpenId.RelyingParty" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly -->
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.OpenId" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.OpenId.RelyingParty" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.OAuth.Consumer" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.OAuth" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.1402.2112" newVersion="4.2.1402.2112" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
    </assemblyBinding>
  ...
 </system.net>
</configuration>

4 个答案:

答案 0 :(得分:1)

注意:Microsoft-Web-Helpers已替换为Microsoft.AspNet.WebHelpers。您应该首先删除旧包,然后安装较新的包。

我打开了NuGet包管理器并安装了包Microsoft.AspNet.WebHelpers并开始工作。请注意,当您创建新的MVC 5应用程序并尝试合并SimpleSecurity或SimpleMembership时,您将遇到同样的问题,因为默认情况下未安装Microsoft.AspNet.WebHelpers。它必须存在才能使SimpleMembership正确运行。

我验证了升级后参考应用程序中的所有功能都正常工作。甚至使用Postal工作的电子邮件的生成,我也不确定,因为Razor的升级也是如此。

我需要对SimpleSecurity程序集进行的一项更改是删除过滤器AuthorizeAttribute和BasicAuthorizeAttribute并将它们放在单独的程序集中。我这样做是因为它们依赖于MVC和Web API程序集。所以现在有MVC的版本和MVC 5的另一个版本。

参考此链接: http://ctsoftr.com/upgrading-from-asp-net-mvc-4-to-5/

答案 1 :(得分:0)

首先,如果可能,我建议使用Visual Studio 2013 for MVC 5

似乎你已经尝试了很多东西,但我重申一些事情(因为它可以帮助其他有同样问题的人)必须检查和可能是问题的原因:

  1. 更新所有nuget包。 (通过packages.config,你似乎已经完成了它)

  2. global.asax中,更改:

    WebApiConfig.Register(GlobalConfiguration.Configuration);

    GlobalConfiguration.Configure(WebApiConfig.Register);

  3. 删除使用包管理器中的以下命令安装的以下任何ASP.NET NuGet包:

    Uninstall-Package -Id Microsoft.AspNet.WebPages.Administration
    
    Uninstall-Package -Id Microsoft-Web-Helpers
    
    Uninstall-Package -Id Microsoft.AspNet.Mvc.FixedDisplayModes
    

    (似乎你也这样做了。)

  4. 在web.config中确保这些更改存在:

  5. <runtime>/<assemblyBinding>部分中,确保正确newVersion在那里:

    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <!--Two elements removed for Clarity -->
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
        </dependentAssembly>
        <!--WebGrease element removed for Clarity -->
      </assemblyBinding>
    

    5。在web.config中找到<appSettings>部分,并将网页:版本从2.0.0.0.0更新为3.0.0.0 ,如下所示:

     <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="PreserveLoginUrl" value="true" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>
    

    6。删除Full之外的所有信任级别,如:

    <securityPolicy>
       <!--<trustLevel name="Medium"  policyFile="web_mediumtrust.config"/>-->
    </securityPolicy>
    

    7. 更新Views文件夹

    下的web.config文件
    • 将包含System.Web.Mvc的所有元素从版本“ 4.0.0.0 ”更新为版本“ 5.0.0.0 ”。

                                       `

      -->
          <pages
              validateRequest="false"
              pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
              pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
              userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
              <controls>
                  <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
              </controls>
          </pages>
      </system.web>`
      
    • 将包含System.Web.WebPages.Razor的所有元素从版本“ 2.0.0.0 ”更新为版本“ 3.0.0.0 ”。如果此部分包含System.Web.WebPages,请将这些元素从版本“ 2.0.0.0 ”更新为版本“ 3.0.0.0

      <configuration>
          <configSections>
              <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                  <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
                  <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
              </sectionGroup>
          </configSections>`
      
    • 如果您在上一步中删除了Microsoft-Web-Helpers NuGet包,请在PMC中使用以下命令安装Microsoft.AspNet.WebHelpers

      Install-Package -Id  Microsoft.AspNet.WebHelpers
      
    • 如果您的应用使用User.IsInRole()方法,请将以下内容添加到Web.config文件中。

      <system.webServer>
          <modules>
              <remove name="RoleManager" />
          </modules>
      </system.webServer>`
      
    • 从项目文件中删除MVC 4项目类型GUID。

      • 在Solution Explorer中,右键单击项目名称,然后选择Unload Project。
      • 右键点击该项目,然后选择修改ProjectName.csproj
      • 找到ProjectTypeGuids元素,然后删除MVC 4项目GUID,{E3E379DF-F4C6-4180-9B81-6769533ABE47}
      • 保存并关闭打开的项目文件。
      • 右键单击该项目,然后选择“重新加载项目”。

      希望它会有所帮助。

    来源:www.asp.net/mvc/tutorials

答案 2 :(得分:0)

我有同样的错误信息,它与一个已更改但未正确更新的软件包有关(不知道为什么,不知道如何,你可以想象这个错误带来的快乐)..我扔掉了我的包文件夹并重建了项目等等......几个小时后我又回到了编码

答案 3 :(得分:-1)

以下是完整的官方迁移指南:

How to Upgrade an ASP.NET MVC 4 and Web API Project to ASP.NET MVC 5 and Web API 2

主要变化包括:

  • 中等信托不再可用(现在应使用完全信任);

  • 现在应该使用与MVC 5和Web API 2兼容的软件包。