【问题标题】:ASP.Net MVC 5 -Attempt by security transparent method 'WebMatrix.WebData.SimpleMembershipProvider.ValidateUser to access security method failedASP.Net MVC 5 - 尝试通过安全透明方法'WebMatrix.WebData.SimpleMembershipProvider.ValidateUser 访问安全方法失败
【发布时间】:2015-06-20 17:10:58
【问题描述】:

我在我的 asp.net web api 项目中使用 Simplemembership。当我尝试使用以下代码验证用户时,出现错误(错误 1)

 if (!Membership.ValidateUser(username, password))
       {
         throw new ValidationException("Username or pwassword is incorrect.");
       }

错误 1:

通过安全透明方法尝试 'WebMatrix.WebData.SimpleMembershipProvider。 ValidateUser(System.String, System.String)' 访问安全性 批判法 'System.Web.WebPages.StringExtensions.IsEmpty(System.String)' 失败。

早些时候我遇到了类似的错误(错误 2),我通过安装这些软件包解决了这个错误:

Install-Package Microsoft.AspNet.WebHelpers

Install-Package Microsoft.AspNet.WebPages.Data

错误 2:

通过安全透明方法尝试 'WebMatrix.WebData.PreApplicationStartCode.OnConnectionOpened( System.Object, WebMatrix.Data.ConnectionEventArgs)' 访问安全性 关键方法'System.Web.WebPages. HttpContextExtensions.RegisterForDispose(System.Web.HttpContextBase, System.IDisposable)' 失败。

我确实清理了解决方案并尝试了,仍然得到同样的错误, 我是否需要安装更多的软件包,甚至简单的会员资格在 web api 中是否有效?

【问题讨论】:

    标签: validation authentication asp.net-web-api asp.net-mvc-5 simplemembership


    【解决方案1】:

    对我来说,当前的解决方法是升级到 .Net 4.5.3。我沮丧地想到了这一点。在升级到网页 3.2.3 后,此问题不仅会影响 MVC 5,还会影响核心 Webmatrix 项目。我认为这是一个框架问题,将通过新的 Microsoft 标识来解决。我目前的修复如下: 注意:请使用 Visual Studio 中的属性页向导将您的目标框架更改为 .Net Framework 4.5.3。它将更新您的 web.config

    <compilation debug="true" targetFramework="4.5.3">
      <assemblies>
        <add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      </assemblies>
    </compilation>
    

    第 1 步:安装包 Microsoft.AspNet.WebHelpers

    第 2 步:安装包 Microsoft.AspNet.WebPages.Data

    第 3 步:[可选] Install-Package Owin

    第 4 步:通过属性页对话框将 targetFramework 更改为 .Net 4.5.3

    【讨论】:

    • 感谢@Ifeanyi-我没有升级到 .Net 4.5,而是将 webmatrix 项目升级到 3.0。
    猜你喜欢
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-15
    • 2014-06-09
    • 1970-01-01
    • 2014-11-06
    • 2013-10-04
    相关资源
    最近更新 更多