Add Identity after creating an MVC website in VS2015 - c#

when I create an MVC website in VS2015 I can select Individual Identity, so the project will come with all the Account stuff.(like Login, logout, [Authorize] ...)
the question is:
if I just created a new Project with choosing: no Authentication.
and I wanted to add the Account stuff.
is there a way to do it automatically without the need to write everything from scratch? (specially the Authorize Attribute and register it in Principal)
And if not, what ist the easiest way to do a simple login?
thank you.

It can be done, If you're looking for Microsoft Identity it's available as a nuget package: https://www.nuget.org/packages/Microsoft.AspNet.Identity.Owin/
But be aware that installing it this way will not auto generates all the stuff the project template does you'll have to do some manual implementation. I recommend making a new site with Authentication and look at it to see what's missing and need to be added manually.

Related

account folder does not show asp.net core web app project

I have created a project with asp.net core web app with individual authentication now I want to edit the registeration page but I cant find it. In the documentation page say go to /Areas/Identity/Pages/Account/RegisterConfirmation.cshtml.cs.
However, I cant find the account folder inside my Pages folder
so what do you think I have done wrong with project?
Thanks
I believe you are looking to add Identity into your code. You would need to scaffold identity before you could see those codes. In summary, you would need to:
Create the project
Scaffold identity
Configure email sender (if any)
The official documentation is actually pretty straightforward and easy to follow.
"I cant find the account folder inside my Pages folder":
I think you are searching this URL
https://localhost:44374/Identity/Account/Register into your project
folder and finally you got to see below page: and there is no Register page
"So what do you think I have done wrong with project?":
No you haven't done anything worng with the project at all. While we
create the proejct with enabling the individual authentication it
doesn't create any Register page within the project as its build in
with the SDK which is not visiable in the project directory
Areas\Identity\Pages\ You can see the DLL files as below location.
Note: If you want to get that source code files then you can get from our official repository here. If you want to customize your identity then you can follow the guideline here
Hope above steps guided you accordingly.

MVC - user name and password from my database

I am a new to MVC and I need some assistance attaching my account details from my SQL database to the account controller.
When you create a MVC project you have the account setting all set up.
I have attached a database and would like to use my database to add/remove users.
How do I go about modifying the current account code to use my database users?
Thanks
Did you create your MVC project from a template? This is always a good place to start I found. It gives you a nice road map to understand how MVC works. I have started from here on a number of projects and just built out from here.
Open a blank web project in VS and then go to the Package Manager then copy this line in the window: http://www.nuget.org/packages/Microsoft.AspNet.Identity.Samples/2.0.0-beta2
There are other templates like this. But this is a good place to start. It primarily deals with Authentication because of the Identity piece but it has th4e basic MVC bit in there that is quite simple.
One way is that you can add field to the userViewModel. This also need to be done for the applicationUser class and then these will bubble through to the tables.
I am not sure if this is what you want but it seems that you are using template with authentication selected. If that is the case you will have asp.net identity authentication and authorization as built in feature in your template. If you don't want to use that in-built authentication you can select none for authentication while creating project and then you can implement you custom authentication in project. For custom authentication you can follow below links
http://www.dotnettricks.com/learn/mvc/custom-authentication-and-authorization-in-aspnet-mvc
https://www.codeproject.com/Articles/1111522/Custom-Authentication-and-Authorization-in-MVC

Asp.Net 5 (vNext) - How to implement custom password verification etc

I'm prototyping a web application using ASP.NET 5. The template project Visual Studio 2015 creates is useful, but it uses Entity Framework which I don't want to use. I already have my own logic for verifying passwords to login, create new users etc. using ADO.NET.
For example, the template project uses functions like SignInManager.PasswordSignInAsync(email, password, rememberMe, false);, but I want to implement my own code for doing this, I'm not sure where I can override this behaviour.
I suspect the config code in the Startup class needs to be changed, this code for example:
services.AddIdentity<ApplicationUser, IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();
Looks like it is setting up the identity logic to use the EF, I imagine I need to implement my own versions of IUserStore and other interfaces, but I'm not sure where to start and I can't find any examples of how to do this.
thanks
First rule of security DO NOT CREATE YOUR OWN SECURITY.
Do NOT write your own PASSWORD VERIFICATION.
Now that's out of the way.
You are allowed to write your own Identity Store.
Check out the official tutorial.
The basic premise is that you Implement your own IUser<T> and a IUserStore<IUser<T>> that allows the .net identity provider to access your storage. However at the end of the day...there should be a ADO.Net Identity Store.

Include authentication MVC4 project

I'm in a trouble, I guess.
I've created an ASP.NET MVC 4 project without default authentication, well, my problem now is add an authentication to this project, note, I've been working it since four months, then I have a system working, but I don't have authentication.
So my question is: What must I do to achieve this authentication?
PS.: If you need some code or config file ask in comments, I've no idea what I must to paste here.
you have to add AccountController and
views from Account folder in Views
you need _LoginPartial.cshtml
also _Layout.cshtml looks differently (because references to _LoginPartials)
Remember about making sure, if connection string in WebConfig file was created correctly.
When it comes to references, use following:
Microsoft.AspNet.Identity.Core
Microsoft.AspNet.Identity.EntityFramework
Microsoft.AspNet.Identity.Owin
The question is - do you want to use built-in external login facilities? (via Twitter, Facebook, Google etc.) Because there are more namespaces required in that kind of situation.

Using the "default" login system for a new MVC application

I've just created my first ASP.NET MVC app. Since I didnt choose to create an empty project, visual studio generated some views for me, including a register user page.
But what tables would i need to create to make use of the register/login-functionality?
Use the aspnet_regsql.exe tool to create your membership database.
http://msdn.microsoft.com/en-us/library/ms229862(v=vs.80).aspx
You actually don't need to create any user tables at all. Try and register and you'll see that the first time you do, it takes a little while to complete the operation. This is because the ASP.NET Membership table structure is being created for you.
However, in Visual Studio, you can go to Project->ASP.NET Configuration which will open a browser window for you to enable you to configure accounts more easily.
If you want to add the ASP.NET Membership tables to your own database, which allows you to add custom tables relating to and extending the functionality of the default membership, you can do so by following the steps in this answer.
You must use the ASP.NET Web Administration tools. Official instructions are provided for you here, including information about the database for your users/passwords.
http://www.asp.net/guided-tour/s27.aspx

Categories

Resources