How to start developing a Web Api 2.2 project with Asp.Net MVC 5 - asp.net-web-api2

I have an MVC5 Project and Non browser project. We just upgraded from MVC4 to MVC5 and included a Web Api project. Now we want to make use of Web Api 2.2 and we have created some HTTP methods which works fine in our Api Project. My question is how should I start with Authentication/Authorization.Do I need to create an Authentication Filter class inheriting from ActionFilterAttribute. I referred this link How should I begin with . I am confused how should I use the IPrincipal and set the Identity. Any help is highly appreciated.

The new version is called ASP.NET Identity framework - There are some changes from the ASP.NET Membership in the table structure and everything works through Entity Framework, the tables are created using code first but you can also create it using a script, for example: identity.codeplex.com and SQL-script-for-creating-an-ASP-NET-Identity-Databa or you run the solution using a valid SQL connection string and the tables will be created on first run (code first is doing that - it's built in the entity framework)...
When you create a sample MVC project you will have the basic functionality
Also, check out these resources:
http://johnatten.com/2013/11/11/extending-identity-accounts-and-implementing-role-based-authentication-in-asp-net-mvc-5/
http://johnatten.com/2014/06/22/asp-net-identity-2-0-customizing-users-and-roles/
http://johnatten.com/2014/10/26/asp-net-web-api-and-identity-2-0-customizing-identity-models-and-implementing-role-based-authorization/
http://johnatten.com/2014/02/13/asp-net-mvc-5-identity-extending-and-modifying-roles
http://www.asp.net/identity/overview/getting-started/aspnet-identity-recommended-resources
http://www.asp.net/mvc/overview/getting-started
http://johnatten.com/2014/04/20/asp-net-mvc-and-identity-2-0-understanding-the-basics/
Also, the new table primary keys are changed so the code can run on any type of database, so it's a 128 string key by default (just between us - the database optimization could be made a little better than this) if you're looking for some trouble, check out these links as well:
https://github.com/TypecastException/AspNet-Identity-2-With-Integer-Keys
https://github.com/TypecastException/AspNet-Identity-2-Extensible-Project-Template

Related

I want To use EF Core 3.1 in Asp Net Core With Database First Approach And also wants to use Identity in my Project

I have used ef core in my asp.Net Core project . What I want to do is , i wants to use Database First Approch with EF Core And Identity but whenever i am scaffolding my db Context it is overriding all previous changes i have made for Identity such as user class inheriting from IdentityUser and all .And I am Also new to this so u can provide some resources to refer.
"The main problem with database first approach : You should never change the model manually and start renaming things etc. Except if you are 100 % sure that your database won't change anymore. If you'r not 100 % sure, just code with the model that has been auto-generated.
Re-Scaffolding will overwrite any changes made directly in the model class, erasing all what you have changed or added."
Check out this explanation, I hope it helps:
https://entityframeworkcore.com/knowledge-base/40344526/entity-framework-core-database-first-update-after-initial-scaffold-

Modify Log in page text in ASP .NET Core

I am using the standard new ASP.NET Core 3.1 + Angular project template and I am trying to find the text displayed on the standard Log In page:
This is displayed at https://localhost:xxxxx/Identity/Account/Login
Searching all files in the solution for any text from this form returns no results and I am starting to think it's in a DLL or some other place I don't see. Is that the case?
Where can I modify that text?
ASP.NET Core provides ASP.NET Core Identity as a Razor Class Library. And it enables us to apply the scaffolder to selectively add the source code contained in the Identity Razor Class Library (RCL), then you can modify the code and change the behavior based on your actual scenario and requirement.
For more information about "Scaffold Identity in ASP.NET Core projects", you can refer to this doc: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-3.1&tabs=visual-studio
This appears to have been moved into a Razor Class library, source here.

MVC based authentication templates in ASP.NET Core 2.0

When creating a new ASP.Net Core web project in ASP.Net Core 2.0, and choosing the 'Individual account' authentication option, the authentication views/controllers where originally implemented using ASP.Net MVC. Recently it appears they have been updated to use Razor pages. My questions is...is there a way I can revert the new project template to using the MVC instead of Razor pages or at the very least is there a way I can see what code the MVC template used to create?
Simply, no. Identity now comes with a Razor Class Library containing a default UI, which as you've noted, is Razor Pages-based. If you want the old-style MVC setup, you'll need to create it yourself. You can scaffold the Default UI pages into your project and then refer to these to move code into controllers/views. Then, when you're done with that, remove the default UI pages in your project, and turn off the default UI in general by using AddIdentity<TUser, TRole> instead of AddDefaultIdentity<TUser> (which adds the default UI under the hood).
FWIW, I used to be totally opposed to Razor Pages until I endeavor the same thing you're about to embark on. After moving all the code into controllers, I started to remember how much of a mess it actually was. There's so much boilerplate code involved in auth: sign in, sign out, registration, password resets, 2FA, third-party login, etc. You end up with monstrous controllers with hundreds or even thousands of lines of code. Even if you try to break it up into many different controllers, that just kind of makes it worse. Long and short, Razor Pages actually works pretty well for something like this. It keeps each unit of functionality self-contained, so you know exactly where your need to go to edit stuff. I'd encourage you to give it a go as-is, first, and see how it works for you.
Also, one of your main concerns may be the Web Forms style of routing with Razor Pages, where you the path becomes the URL, and if you're like me, that probably offends your sensibilities. This can actually be changed, though it's not documented well at all. You can simply specify whatever route you'd like the page to have with the #page directive. For example, you could do something like following in Login.cshtml:
#page "/signin"
Then, you can access the page via /signin, instead of /Identity/Account/Login.cshtml.

Update two partial views when any column gets updated

I have a page in which there are two partial views, one to the left and the other to the right. I would like these two views to be refreshed automatically when the tables that they are related to gets updated. Is SignalR the best option? and Is it complicated to implement this to an existing project? Right now I am using javascript 'set interval' to update every few seconds. Instead of doing constant polling I want to update the views only when the data gets refreshed. I am new to SignalR.
This is a ASP.NET mvc project,I want to update these two views only when the information pertaining to this user gets updated.
Please advise!
SignalR is a better option when compared to requesting for update in a regular interval since SignalR solution gives you more instant updates on your UI.
In your case, you might have to send out broadcasts from the server as soon as you update the backend tables.
Is it complicated to implement this to an existing project?
That's upto the architecture of your project, however implementing it in an MVC application is not so hard.
Here is an example of how SignalR is implemented in an MVC project.

How to implement Breeze with NHibernate and webapi 2

I'm trying to implement some days Breeze in my project with NHibernate and webapi 2 but without success.
Examples on github are for webapi 1
I'm having several problems, among them:
Not exist BreezeNHController in webapi 2
With IUnitOfWork architecture, ContextProvider was confused.
I tried to add the attribute BreezeController to the controller but to perform the action {{odata}}/GruposUsuarios?$filter=substringof('Vivo', Nome) still having trouble translating the query.
The main objective is to use Breeze to perform queries using odata queries as substringof and expand.
Any help will be appreciated!
The nuget package is now available, and the NorthBreeze sample
is now updated to use Breeze 1.4.8 and WebApi 2
With this update, your queries should be working in Web Api 2. Please let me know if they are not. Thanks.