Overriding ASP.NET Membership in ASP.NET MVC 4 - asp.net-membership

In previous versions of ASP.NET I could modify the Membership Provider settings in web.config to point to my custom implementation.
I'm trying to emulate this in MVC4, but it appears things have changed a little in the template. It appears to be using WebMatrix.WebData.WebSecurity instead of the classic Membership classes. Do I need to strip all that stuff out and replace it with the Membership calls like I previously did, or is there a way to use the new WebMatrix.WebData.WebSecurity classes with my custom Membership implementation?

You will have to strip out all the stuff and replace with membership calls if you want to continue using your custom membership implementation.
SimpleMembership(webmatrix.webdata.websecurity) will not work with existing membership implementations

Related

MVC3 - Is it good practice to use the membership DB that is created on a default web app?

So I'm trying to create an MVC3 web app. I decided to use EF taking care of my database first, instead of using the code first or model first approach.
So, in terms of membership, is it good practice to use the auto-generated ASPNETDB.MDF going forward, and mapping my EF database to it? Or should I scrap it and add membership to my EF database?
The membership system is well known, tested, and functions well. You should use it, unless you have a good reason not to. Even then, you still should use the base IPrincipal and IIdentity functions that Membership and FormsAuth implement.

how to develope Independent User control in mvc3 with controller

I am building the User control in mvc. I want to write the controller for the user control where actions should access the WCF web service and its methods. What i need to do. is MVC3 supports bussiness logic classess for User control like normal asp.net supports .cs file as code behind to user control. I don't want to write any server side code in .ascx file. what should i need to do ?
some how usercontrol should be generic with isolated business logic.
This question has been asked an answered here. MVC 3 does not preclude you from using web forms approach that you are used to. But anyone one would benefit from using Razor, which is large paradigm shift from the use of webforms and takes a very different approach to the concept of reusable controls.

Getting own EF 4.1 Code First classes to work with .NET Membership

I am working on a simple web application that is built with EF 4.1 Code First and MVC3. My Domain Model sits in a project outside the MVC3 project.
I have gotten to the stage where my web application is more or less complete. However right now, my application doesn't have any form of authorization or authentication. So a regular user can get to Actions and Controllers that only an Admin is suppose to have access to.
My question is, how do I get my web application to work with the .NET Membership ? Because I am aware that the .NET Membership has many database tables of its own !
My knowledge is fairly limited, thus any clear, easy to follow responses would be greatly appreciated.
After the Membership is set up, I know my way around applying Authentication and Authorization to Actions and Controllers.
Thank You.
Go into your C:\Windows\Microsoft.NET\Framework\v2.xx or v4.xx\ and execute aspnet_regsql, this will launch a wizard that allows you to choose your database and it will add the stored procs and tables to allow membership to function.
Then you run the ASP.NET configuration wizard (the little toolbox icon at the top of your solution explorer) and then configure your roles and accounts. See this page and skip to the Configuring the website for membership and roles section.
ASP.Net membership is actually kinda interesting and frustrating to an extent. To you run a tool called aspnet_regsql.exe found in your Windows\Microsoft.net\Framework folder which generates all of the necessary tables to get it running. Next move onto your Web.config file. If you started with your basic ASP.NET MVC 3 template then you should have a <connectionStrings> entry under the name "ApplicationServices". Change that to your database connection string. This is what the membership provider uses to hook everything up. If you look through the rest of the config file there should be sections for <authentication>, <membership>, <profile>, and <roleManager>. These deal with the various sections and settings that the ASP.Net user management is broken into.
At this point everything should be hooked up. If you select your project in the solution explorer, a little red hammer icon should appear. This is the ASP.NET configuration manager. You can use this to set up different profiles and manage different users.
Now this stuff won't be connected to your EF4.1 code first stuff at all. Instead, you can interact with your membership provider through static classes Membership and Roles. If you take a look at the AccountController on a default ASP.Net MVC 3 Internet application template it will give you a good idea how it works.
After working with this stuff for several months, I found it much easier to basically write your own. Tying things together eventually becomes a huge pain and there is a whole lot of extras that the membership provider gives you that is unnecessary for small applications.

Is a good idea use Membership Provider with ASP.NET MVC

In ASP.NET MVC we dont have Login controls of webform, then still make sense use Membership Provider? It is a good practice?
Membership Provider is agnostic of Web Forms or any other classes where it will be used, so the least I can say is its not a bad idea.
The Membership Provider is just a data store, use it as you wish. There just happen to be ASP.NET forms controls that also know how to use it.
Yes, it still makes sense. Take a look a the default project created by Visual Studio (not the empty one), to see how it can be used with ASP.NET MVC and unit tests.

What new features would you like to see in Asp.net MVC 3?

Asp.net MVC 3 preview 1 was released at the end of last month. Are there any new features you are excited about or any features you would like to see before it is fully released?
Full support for Controllers with Generic Parameters
public GenericController<SomeType> : Controller
Generic controllers are quite possibly the greatest MVC timesaver if your doing a lot or business CRUD. There are so many similarities between the Add methods of almost every MVC project that it makes sense to abstract these operations out in a Controller that fits all scenarios.
Right now its a little hacky to create a generic controller. The MVC engine always gets the name wrong (GenericCo vs. Generic) and without full support plugin and libraries that interact with controllers just fall over when they encounter a generic one.
Make Dropdowns easier to work with
As a professional MVC tag watcher I've noticed that working with dropdowns is one of the most repeated questions on SO. The amount of Dropdown questions is a strong indication that something should be done to make it easier or less ... complex?
make checkbox list easy to work with
add T4MVC to the official release
add official helpers for OData
support one javascript library either MS Ajax or jQuery(preferably)
I wish they can add something to help developer to migrate their previous ASP.NET WebForms application.

Resources