Use asp.net authorize in .net core - asp.net

i want to know asp.net authorize function can it be used in .net core?
Or something can instead in authorize for .net core? thanks

You can use Microsoft.AspNetCore.Identity with Identity Server 4 to authorize your application.
The tutorial from MS is Here.
In short, you can change Authentication to Individual User Accounts when create new projects. Or you can scaffold Identity into an exist project
For example, you can scaffold Identity into an empty project:
From Solution Explorer, right-click on the project > Add > New Scaffolded Item.
From the left pane of the Add New Scaffolded Item dialog, select Identity > Add.
In the Add Identity dialog, select the options you want.
Select your existing layout page, or your layout file will be overwritten with incorrect markup:
~/Pages/Shared/_Layout.cshtml for Razor Pages
~/Views/Shared/_Layout.cshtml for MVC projects
Blazor Server apps created from the Blazor Server template (blazorserver) aren't configured for Razor Pages or MVC by default. Leave the layout page entry blank.
Select the + button to create a new Data context class. Accept the default value or specify a class (for example, MyApplication.Data.ApplicationDbContext).
Select Add.
Then generate Identity database schema:
Install-Package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
Add-Migration CreateIdentitySchema
Update-Database

Related

asp.NET MVC Identity login page - Where is this pointing to?

I just started some tutorials on MVC (I'm an old .net framework programmer).
In the pre-configured ASP.NET MVC Web App setup (in Visual Studio 2019), I'm trying to find where the actual Login page is (the HTML). I assume this is pre-built into Microsoft Identity. Is there any way to change this login form?
These are scaffolded items Microsoft generated for you for using identity users. You have to follow some steps to add them to your project.
Press the right mouse button on your project.
Press Add
Add a new Scaffolded item
Select the identity options and click add.
Now you can a list of pages. You can select all the pages you want to use in your project. Select the data context dropdown value. The default value will generate an Application db context class for you and install the necessary packages.
Now you can see you have some extra files in your project/Areas/Identity/Pages folder. you will also find a folder named 'data' that implement Applicationdb context.

Why CRUD razor pages in ASP.net CORE does not work out-of-box after Scaffolding with Database-first approch?

in VS 2019 i have created an web-app like this:
After that i have:
Created a database, and added it in VS2019 "SQL server explorer" (so connection is fine)
Then Scaffolded according to the command in the lasted post here: https://github.com/dotnet/efcore/issues/19986, and i get my "class/model" as a result of this.
Then I add my CRUD pages like demonstrated in this video: https://www.youtube.com/watch?v=q2u1VY28Drs
And that is ok, since the CRUD pages are created (Exists in solution explorer).
Now when i start the app, and manouver to the new CRUD pages as shown i the last video link, it does not work out of the box, the page does not exist: No webpage was found for the web address: https://localhost:44335/V2/index. I dont understand why, but suspect it has something to do with routing.
Or, what could be the problem here?
tnx
Updated 19.10
I create a MCV app, and follow the steps 1&2 above, then i follwo this guide at the "Add model" step: **https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/?view=aspnetcore-3.1 ** and
then add this: using Microsoft.EntityFrameworkCore; in my startup file. I do not add using MvcMovie.Data;
And it still do not work, the documentation is lacking to be mild on the database first approach. What do i NEED to do from the step: "Add a Model" in the MVC guide? anyone?
Or, what could be the problem here?
The key of this issue is that the project in this video is in asp.net core razor page rather than asp.net core mvc.
When you create the project, in Create a new ASP.NET Core web application box ,you should choose the template of Web Application, you can have a look for official documents:
Then you can follow the video operation to create the crud pages.
If it is in the asp.net core mvc project, you need to create New scaffolded Item in the Controller folder and should select MVC Controller with views, using Entity Framework template, you can have a look for this.

.NET Core Web Api cannot access the models folder

I have two project in my solution. MVC and WebAPI. I added the WebAPI project later. I added new controller and Models folder in WebAPI project. But I can't create a new instance of my model in the controller. I get "The type or namespace name 'Category' could not be found..". It also doesn't allow me to bind the name using.MyProjectAPI.Models.
What should I do?
Right-click on Reference and click Add Project Reference

ASP.NET Core Identity - where is Account Controller and Folder

I am new to .NET Core and wanted to ask about Identity.
I bought a book and followed all the instruction. It is very simple to set Identity the way the book describes.
Create an Account Controller, LogIn, Logout views etc...
But when I create a new project with Visual Studio with Individual User Accounts selected.
I can't find the Account Controller folder. There is an Areas folder but almost empty. Areas\Idnetity\Pages\_ViewStart.html.
I checked hidden files etc, but couldn't find Account or Identity Folder.
The login link is like this
https://localhost:44313/Identity/Account/Login
Identity is working but where are the codes?
As this entry states:
In ASP.NET Core 2.1 we can now ship Razor UI in reusable class
libraries. We are using this feature to provide the entire identity UI
as a prebuilt package (Microsoft.AspNetCore.Identity.UI) that you can
simply reference from an application.
Notice that you are asking this feature to be effective by adding .AddDefaultUI(UIFramework.Bootstrap4) to ConfigureServices method.
If you still love to scaffold the Identity as old days, use this cli command:
dotnet aspnet-codegenerator identity --useDefaultUI
For more information on scaffolding options visit here.

How do I update the default database in ASP.NET 2013?

So I created a website in ASP.NET 2013 and went through the login so the sample db would be created. Then I added some tables. Now I wanted to customize the AspNetUsers table with my own properties that I add to the ApplicationUser class. However when I add properties to the class and try to run the Update-Database command in the PackageManagerConsole, it fails with a "The parameter is incorrect" message. I thought this would be the way to go as I believe this is considered CodeFirst. This is an ASP.NET 4.5 VB Web Forms App.

Resources