Reputation: 5594
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
Upvotes: 4
Views: 1195
Reputation: 1039478
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.
Upvotes: 6