简体   繁体   中英

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.

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. Any direction would be appreciated

Edit It is something to do with the [InitializeSimpleMembership] attribute that sits on an MVC4 Controller. This performs some Initialisation for 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

Forget about it. The Membership provider is tightly coupled with the ASP.NET context and not intended to be used in desktop applications. It depends on things like HttpContext, cookies, ... which do not exist in a desktop application.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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