I am new to MVC, Have created simple application (very basic, only 1 controller) & used Entity Framework as ORM.
There is form for Registration in application, when I fill up that form user is registered & able to login with those credentials.
But there is no table created in my Database, so my question is where this registration information is stored?
I know this need knowledge of May be Membership/forms authentication, but I don't know them also.
I tried to search google for this, but may be I am not able to predict what to search.
EDIT :
Following is tag of DefaultConnection
Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-AKShop-20140808100025.mdf
I think that standard DB was created for your membership. Probably at app_data\aspnetdb.mdf.
Before MVC 5, MembershipProvider or SimpleMembershipProvider by default, and data is persisted in (local) SQL server.
In MVC5, ASP.NET Identity 2.0 by default, and the data is persisted through Entity Framework which by default point to MS SQL, though it is easy to switch the persistence to other DB engines.
Identity 2.0 is quite new, and the official release is April this year, so this is why you got mixed info when searching the Internet. Nevertheless, if you have a green field MVC project, it might be better of to use MVC 5 and Identity 2.0.
Related
I am working in a MVC project that contains both regular MVC controllers as well as Web API Controllers. Initially I implemented Forms Authentication with custom user table. But now I am planning to use the new ASP .NET Identity and change from the forms cookie based authentication to claims based authentication and authorization. I already have a database with tables with custom fields. So I need to customize the ASP .NET Identity to work with my tables
Can anyone guide me on how this can be achieved ?
Edit:
In reply to FKutsche, here is the User table that I have. I have kept only the columns that matter.
User Table
UserId
UserName
Password
UserTypeId
User Type Table
UserTypeId
UserType
The column names are self explanatory so I am not describing them. The User Table has foreign key on UserTypeId column to the UserType table.
There's no point in making this kind of migration if you're not going to use the Identity table format.
ASP.NET Identity has an outstanding out-of-the-box list of features that simply cannot exist without the appropriate db support (and that user table is not capable of providing them).
I think you have different options here:
stick with your user table and build a custom oauth provider on it (it's not too difficult, please check this link - I personally built the security layer of many apps following this guide)
migrate to a brand new identity model with ASP.NET identity and link this table as an extended claim to the IClaimsIdentity generated for the logged user (check this SO answer for example).
IMHO, I personally prefer the second option: you have to migrate your user ids and passwords to the new system, but it's better to start with something solid and well tested. This way you will also have access to future improvements, which is probably not true with a completely customized system without a big coding effort.
Hope it helps :)
I must have missed this somewhere (or slept through the class)... the standard ASP security tool for managing users and roles seems to be absent when using the new simple security version. That is, the original is there and working, just points to traditional ASP security... NOT to the new "simple" system.
In my project I can log in, I can look at the webpages_ tables but can find no method of accessing them in my project... I would be happy to manage roles and get the USERID and maybe ROLEID so I could tie the user to other functions in my project.
I've looked through hundreds of posts and articles... normally I find I am missing some minor config entry or something but this time I am a little more stuck.
Advice is appreciated.
Thanks!
SimpleMembership does not work with the Web Site Administration Tool (WSAT). There is a good overview of SimpleMembership in this blog. Here is a quote from it.
WSAT is built to work with ASP.NET Membership, and is not compatible with Simple Membership. There are two main options there:
Use the WebSecurity and OAuthWebSecurity API to manage the users and
roles.
Create a web admin using the above APIs.
Since SimpleMembership
runs on top of your database, you can update your users as you would
any other data - via EF or even in direct database edits (in
development, of course)
I would also add that you can seed some of this information at application start-up, such as what roles are available, as shown in this article.
I try to use OpenId in ASP.NET MVC4, SO I use This Tutorial, And as you see in Database Structure we need some additional tables to support OpenId and OpenAuth, as usual I use
C:\Windows\Microsoft.NET\Framework64\aspnet_regsql.exe
to implement Membership Database,
I install Visual Studio 2012 with .NETFramework 4.5 and MVC 4 so I run the aspnet_regsql.exe but the created database is not contain additional tables to support OpenId, So is there another way to implement this Database? Or I should add additional database by my own? and if yes how implement needed membership structure in Code side?
I think there must be an auto way (like before) to implement membership to support new OpenId feature, what is your suggestion?
By default, MVC 4 does not use the old membership tables, but rather a new membership system called SimpleMembership that has a very different table structure. You don't use aspnet_regsql, but rather let SimpleMembership create the tables automatically.
If you generate a default internet application with MVC 4, it creates all the code necessary to enable openid and openauth. This is built into the default sample. The example you linked to is for the Universal providers. They too, by the way, have a different table structure than the old SqlMembership system.
For some reason, the idea of setting up Membership in ASP.NET MVC seems really confusing.
Can anyone provide some clear steps to setup the requisite tables, controllers, classes, etc needed to have a working Membership provider?
I know that the Demo that MVC ships with has an Accounts controller. However, should I be using this in my own project? What do I need to get my existing database ready if so? If not, how do I learn what I need to do to implement a membership provider?
Check out this step by step blog on how to set up Membership provider in your asp.net mvc project. The sdk tool you need to get your database ready is aspnet_regsql.exe, you don't need to create a separate database to do that ( a lot of people think they have to provide a separate aspnet.db), you can run the command on your existing database, and it will create the tables, views, and stored procedures to handle the membership provider for you.
However, should I be using this in my
own project? What do I need to get my
existing database ready if so? If not,
how do I learn what I need to do to
implement a membership provider?
The benefit to use the default provider (SqlMembership provider) is to save yourself a lot of time. It involves a lot of work to design a complete membership and role provider.
Edit [2014-06-19] Asp.Net Identity Framework is Microsoft new recommendation to manage user sand permissions.
Check out this link:
https://github.com/TroyGoode/MembershipStarterKit
Most of the work is already done for you. Just download the sample project and run the aspnet_regsql.exe against your database.
check out my answer in this post;
membership
If you want to keep the membership provider that .Net creates for you then you can copy all the tables etc to another sql database and point the provider at it via the config file.
Post a comment if you need more than this.
How would you handle membership in an ASP.NET MVC application? Using any external libraries? How would you do OpenID log in? username log in? email log in? any other that is worth looking into? Maybe all of them mixed into the application?
It seems ASP.NET comes with some pre-build user database (I'm totally new to .Net). The NerdDinner example uses it but then it makes the foreign keys use the username. That doesn't sound very good. Do you use this schema of two separate databases or only one? What do you use as the foreign key, any IDs?
I've found ASP.Net MVC Membership, anybody using it? does it work well? can it be expected to be maintained?
Membership Providers are not new to ASP.Net MVC, they were introduced with ASP.Net 2.0.
The Membership Provider model is simply an abstraction layer between your application and whatever source you are authenticating your users against. You can switch providers easily by simply changing your web.config file.
It is easy to write a membership provider, there are many walkthroughs on the web. Typically you would do so if you were using a database that used a different schema than the default examples that come with ASP.Net (which is most of the time). The foreign keys on the username thing in the NerdDinner example is a simplistic example that you would rarely see on any real-world databases.
I would highly recommend using the Membership model. Controls like the Login control are built to make use of it, and it is well-designed and makes it easy to change or combine different login methods for your application. If you want to use OpenID, a quick google search brought up this OpenID Membership Provider.