Include authentication MVC4 project - c#

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.

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.

Add Identity after creating an MVC website in VS2015

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.

ida:Domain un-used setting?

When creating an authenticated C# MVC Project it creates an app setting called ida:Domain
However this is never used anywhere in the code generated and as we're using Open ID I cannot see any benefit to having it in the config.
Please can someone tell me if it is used under the covers by any IIS or Microsoft library and what for?
I found this question unanswered. Although it is late, but still no harm doing that.
These configurations are used by ASP.NET MVC Identity service to manage IDentity and Access (IDA) for Azure Active Directory users.
Hope that helps.

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

Signing key rollover in Azure Active Directory

I am using the method mentioned in the link https://learn.microsoft.com/en-us/azure/active-directory/active-directory-signing-key-rollover#vs2012 to automatically rollover the certificates.
However the below line of code searches for <issuerNameRegistry> as a child element of the <identityConfiguration> which is deprecated according to the msdn link https://msdn.microsoft.com/en-us/library/hh568647(v=vs.110).aspx
ValidatingIssuerNameRegistry.WriteToConfig(metadataAddress, configPath);
Is there any updates coming soon to System.IdentityModel.Tokens.ValidatingIssuerNameRegistry nuget package which searches for <issuerNameRegistry> as a child element of <securityTokenHandlerConfiguration>
I am able to get the code working as there is support for backward compatibility. However I do not want to use deprecated methods
What I found worked best was to use the different versions of Visual Studio and Office 365 to see the differences in approach.
The current way has a little different syntax and all of that can be discovered by using the ASP.Net Web Application template.
If you use the template in vs2013 you will see the setup you must currently have with <federationConfiguration> and <identityConfiguration> sections, TenantDbContext, IdentityConfig and it wired up in your global.asax
If you do the same thing in vs2015 you will see that there is no longer any configuration at all besides appSettings. Everything is magically wired up through a partial class at the root called Startup.cs with more of the content hidden in the App_Start folder. This is the OWIN pipeline and has a much different feel than what you have been used to. For the better. A lot of the identity terminology is the same, the keys are the same, the management in AAD is the same so you get to reuse a lot of your code. OWIN does require MVC5 so if you can't upgrade you are pretty good where you are.
The ValidatingIssuerNameRegistry has been replaced by a TokenCache but the concept is the same, EF store for rollover safety.
More Reading:
Authentication, Authorization and OWIN – Who Moved My Cheese?
Understanding OWIN Forms authentication in MVC 5

Categories

Resources