简体   繁体   English

将WebSecurity与.Net winForms应用程序一起使用

[英]Using WebSecurity with .Net winForms application

I am trying to implement the WebMatrix.WebData.WebSecurity() method in a .Net desktop application, the application will connect to a database on the server together with a MVC4 project so I would like to use the current provider on both applications to authenticate a user. 我正在尝试在.Net桌面应用程序中实现WebMatrix.WebData.WebSecurity()方法,该应用程序将与MVC4项目一起连接到服务器上的数据库,因此我想在两个应用程序上使用当前提供程序进行身份验证用户。

I was wondering if this is possible as I am getting the exception: 我想知道这是否可能,因为我收到了异常:

{System.InvalidOperationException: To call this method, the 
"Membership.Provider" property must be an instance of 
"ExtendedMembershipProvider".
 at WebMatrix.WebData.WebSecurity.VerifyProvider()

I have copied the Web.Config of my MVC4 application into my app.config file but I still cannot seem to get it to work. 我已经将MVC4应用程序的Web.Config复制到了我的app.config文件中,但似乎仍然无法正常工作。 Any direction would be appreciated 任何方向将不胜感激

Edit It is something to do with the [InitializeSimpleMembership] attribute that sits on an MVC4 Controller. 编辑这与MVC4控制器上的[InitializeSimpleMembership]属性有关。 This performs some Initialisation for WebSecurity. 这将对WebSecurity执行一些初始化。 Can anyone see how to initialise this code without it being an attribute? 任何人都可以看到如何初始化此代码而不将其作为属性吗?

Thanks again 再次感谢

Thanks 谢谢

I am trying to implement the WebMatrix.WebData.WebSecurity() method in a .Net desktop application 我正在尝试在.Net桌面应用程序中实现WebMatrix.WebData.WebSecurity()方法

Forget about it. 忘掉它。 The Membership provider is tightly coupled with the ASP.NET context and not intended to be used in desktop applications. 成员资格提供程序与ASP.NET上下文紧密耦合,不适合在桌面应用程序中使用。 It depends on things like HttpContext, cookies, ... which do not exist in a desktop application. 它取决于诸如HttpContext,Cookie等……,这些东西在桌面应用程序中不存在。

What you could do instead is to define a reusable service layer that you could use in your desktop application directly and then have an implementation of an ASP.NET membership provider calling the methods of this service layer, thus reusing the same functionality between the two. 相反,您可以做的是定义一个可重用的服务层,您可以在桌面应用程序中直接使用该服务层,然后实现一个ASP.NET成员资格提供程序的实现,以调用该服务层的方法,从而在两者之间重用相同的功能。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM