简体   繁体   English

在WPF应用程序中使用WebMatrix.WebData.WebSecurity

[英]Using WebMatrix.WebData.WebSecurity in a WPF application

I have an MVC4 internet project that uses the out of the box WebMatrix security. 我有一个使用现成的WebMatrix安全性的MVC4 Internet项目。 A requirement has come along to add a WPF front end to the same application. 提出了将WPF前端添加到同一应用程序的要求。 I have moved the model into a separate DLL and started building the WPF front end over the same entities. 我已将模型移到单独的DLL中,并开始在相同实体上构建WPF前端。

The only issue I am having is trying to integrate with the existing security model. 我唯一的问题是尝试与现有的安全模型集成。 I have added a system.web section into my WPF project's app.config as follows: 我已经在WPF项目的app.config中添加了一个system.web部分,如下所示:

<system.web>
  <membership defaultProvider="SimpleMembershipProvider">
    <providers>
      <clear/>
      <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
    </providers>
  </membership>
</system.web>

Now when I call WebSecurity.Login("Username", "Password") I get the following error: 现在,当我调用WebSecurity.Login("Username", "Password") ,出现以下错误:

You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class. 在调用“ WebSecurity”类的任何其他方法之前,必须调用“ WebSecurity.InitializeDatabaseConnection”方法。 This call should be placed in an _AppStart.cshtml file in the root of your site. 该调用应放在网站根目录中的_AppStart.cshtml文件中。

I have tried calling the InitializeSimpleMembershipAttribute(); 我试过调用InitializeSimpleMembershipAttribute(); code that comes with the MVC project in the start-up of my WPF application, but it makes no difference to the above error. 我的WPF应用程序启动时MVC项目随附的代码,但对上述错误没有影响。

I cannot find any examples on-line of how to do this, am going down a dead end here? 我找不到任何在线示例,该怎么办?

Any help would be appreciated. 任何帮助,将不胜感激。

In the end I decided to take a different approach and use a WCF authentication service to share between my different clients, as outlined in this post Walkthrough: Using ASP.NET Application Services . 最后,我决定采用一种不同的方法,并使用WCF身份验证服务在我的不同客户端之间共享,如本文章演练:使用ASP.NET应用程序服务中所述

This was a neater solution than trying to get web matrix to work directly from inside a WPF project. 与尝试使Web矩阵直接在WPF项目内部工作相比,这是一个更整洁的解决方案。

You need to do two things to get this to work 您需要做两件事才能使它起作用

First in Global.asax.cs add this at the bottom of Application_Start() 首先在Global.asax.cs中将其添加到Application_Start()的底部

    var attr = new MixThread.Web.Filters.InitializeSimpleMembershipAttribute();
    attr.OnActionExecuting(null);

Second, add this to your Web.config 其次,将此添加到您的Web.config

<system.serviceModel>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

You should be able to construct a WCF based login like so: 您应该能够像这样构建基于WCF的登录名:

[AllowAnonymous]
public bool Login(string username, string password)
{
    return WebMatrix.WebData.WebSecurity.Login(username, password);
}

您可能也需要将此添加到服务中。

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用MySql的Webmatrix.WebData.WebSecurity无法正常工作。 WebSecurity.UserExists()检查中引发SQL语法错误 - Webmatrix.WebData.WebSecurity with MySql is not working. Throwing sql syntax error in WebSecurity.UserExists() check WebMatrix.WebData.WebSecurity - 如何只通过PasswordResetToken获取UserName - WebMatrix.WebData.WebSecurity - How can I get UserName by only having PasswordResetToken WebMatrix WebData InitializeDatabaseConnection - WebMatrix WebData InitializeDatabaseConnection WebMatrix WebSecurity PasswordSalt - WebMatrix WebSecurity PasswordSalt WebMatrix中的WebSecurity的PasswordReset无法正常工作 - PasswordReset with WebSecurity in WebMatrix not working WebMatrix.WebData无法从单独的ASP.NET应用程序中读取成员资格信息 - WebMatrix.WebData can't read membership information from a separate ASP.NET application 将WebSecurity与.Net winForms应用程序一起使用 - Using WebSecurity with .Net winForms application Webmatrix.WebData登录方法导致异常 - Webmatrix.WebData Login method results in exception 使用Microsoft Fake Framework MVC4单元测试WebMatrix.WebData - Unit testing WebMatrix.WebData with Microsoft Fake Framework MVC4 是什么导致 WebMatrix.Data.dll 和 WebMatrix.WebData.dll 添加到我的 bin 目录中 - What causing WebMatrix.Data.dll and WebMatrix.WebData.dll to be added to my bin directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM