Asp.Net core Individual User Authentication Login/Register Pages - asp.net-core

I am new to Asp.net core razor pages. I am using asp .net core version 2.2, I am trying to make an application using Social Media authentication services. But the problem I am facing is the weird structure of asp .net core razor applications. I have already done the authentication things, but the problem I am facing is to find the Login and Registration pages. Where can we find them? What if we want to change the layout or something. What should we do for that?

Depending on how you implemented authorization, and based on the documentation :
You should be able to find the scaffolded views in the Areas\Identity's folder of your project or in the ~/Pages/ folder.
If you want to change the layout or something else, you can edit those views (customize) and/or create other ones.
Don't forget to generate the scaffolded views using :
From Solution Explorer, right-click on the project > Add > New Scaffolded Item
Hope it helps.

The default scaffolded Razor pages in ASP.NET Core are made using Partial Views. The default layout of the applicaton can be found in Pages/Shared/_Layout.cshtml.
Inside of this file there is a reference to Pages/Shared/_LoginPartial.cshtml , which contains the layout for the login page. The reference should be somewhere around line 35 in the _Layout.cshtml.
If you want to edit the way the default Razor pages look, this is where you do it.

Related

Using Blazor #bind in Razor page

I have a Razor Page app with forms. Because of necessity of using "dynamic" pictures I would like to use #bind feature from Blazor in the created Forms. I mean exactly as the #bind on the screenshot. Picture is taken from tutorial video [https://www.youtube.com/watch?v=Oeh2IJw7Zig&t=2353s]
Is it possible to add this functionality in Razor Pages Core App? Without "rewriting" all into Blazor webapp type.
Is it possible to add this functionality in Razor Pages Core App?
Without "rewriting" all into Blazor webapp type.
No. Only Blazor support #bind. No document said you can use #bind for ASP.NET Core plain Razor Pages.
Reference documents
https://learn.microsoft.com/en-us/aspnet/core/blazor/components/data-binding?view=aspnetcore-5.0
https://learn.microsoft.com/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-5.0#bind

Blazor WebAssembly - How can I add a new *.razor page that don't need to recompile or rebuild the project

I am developing a survey project which collects data from the client with Blazor WebAssemly for the Client-side. Each survey form will have a different design and edit-checked rule. So I decide when I create a new survey form, the application will generate a new *.razor page automatically, for example, ClientSurvey.razor page. Everything works well until I navigate the web application to the ClientSurvey.razor I just have created. The system shows error:
404 Not found.
I have to rebuild the project again, and it can show the ClientSurvey.razor page on my website.
With ASP.NET MVC before I don't have to rebuild the project when I add a new aspx page. Does it still work with Blazor WebAssembly? If yes, how can I change the razor page, and it can update on my website automatically without rebuild or recompile?
And I also meet a problem that when I deploy the project in IIS, I don't see where the UI (.*razor) pages are stored, I know they are compiled to dll. How can I keep them in raw files in the same way with ASP.NET work? With ASP.NET, when I deploy it in IIS, there is always a folder to store aspx pages.
Updated: please see the figure to more clearly

How to inspect asp.net core methods?

I created a new ASP.NET Core MVC application with individual user accounts authentication. I would like to see how they implemented some methods. I suppose I can do it since ASP.NET Core is open source project, but I can't find these methods in github repository.
https://github.com/aspnet/AspNetCore/
I am highly interested in this method.
https://localhost:portnumber/Identity/Account/Login
Q1: How to find this method in my project and is it possible to debug it?
Q2: Why I dont see AccountController file in my new created app?
ANSWER:
It turned out, that from .net core 2.2 version if you want to see or change Identity controllers, you have to scaffold them manually.
https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.2&tabs=visual-studio#scaffold-identity-into-an-empty-project
The methods you are referring to are part of your application. Have a look under the Areas folder. There should be a subfolder called Identity. Under the Identity folder, you should find the AccountController and your Login action method should be inside this controller.
If you really want to look into the source code you need to have a look at the SignInManager.cs class and see how the SignInAsync method is implemented, which is used by the Login action method.
EDIT
Please refer to the screenshot below
EDIT 2
Structure for the newly created app using Web Application template

Is it feasible to convert an single MVC razor view/page into a SPA?

I currently have an ASP.NET Core MVC application with multiple pages with one particular page having a lot of hand-made javascript code and ajax requests. It's becoming quite hard to manage and I would like to move to a framework like Angular, React etc for this particular page only. It is feasible to convert a single MVC view to a SPA app and still keep the other pages? Does anyone have any references on this? Google is not being too helpful...
The simplest way I have found to do this is to use one of the SPA templates and then add the static pages around that.
Here's an an example project I have made that demonstrates the concept by adding a new Razor Page to the angular SPA template.
To do this for an already existing MVC/Razor Pages app I would suggest copying the following from an SPA template project to the MVC/Razor Pages app:
ClientApp
Controllers (SampleDataController.cs)
Views (Home, Shared)
npm_shrinkwrap.json
package.json
tsconfig.json
webpack.config.json
webpack.config.vendor.json
Startup.cs (copy the SPA things)
This is not an exhaustive list but should get someone most of the way.

Can we use Razor on an existing ASP.NET 4 website?

Is it possible to use Razor on an existing ASP.NET 4 website?
Yes, you can use Razor with an existing ASP.NET WebSite. Simply open your website using the WebMatrix tool and start adding CSHTML files.
One caveat is that if your website is using WebForms controls the WebMatrix tool will not provide any help working with them in existing aspx pages. Additionally, Razor does not support WebForms so you will not be able to add something like <asp:GridView> to a CSHTML file.
You shouldn't even need to open the site in Web Matrix if you already have VS2010 and MVC 3 (which includes the Visual Studio tools for building ASP.NET Razor websites) installed. Installing MVC 3 makes the libraries required for developing Razor pages available, even to existing web applications.
See:
http://www.asp.net/webmatrix/tutorials/program-asp-net-web-pages-in-visual-studio
You don't need to create a new Web Pages site (as per the instructions). You can just open up an existing web site, right click the site's root folder, click add item and you should see "Web Page (Razor)" as an option.
Inellisense and debugging works in the Razor pages just like the Web Forms pages
As stated above, keep in mind that ASP.Net Web Pages (Razor) and ASP.Net WebForms are really different platforms, and the reusable components of each can not (or at least should not) be used
marcind is correct, if you want to open your existing ASP.NET website in WebMatrix and work on it from within the tool. If, on the other hand (or in addition to), you want to use Razor syntax in your site and stay within VisualStudio, check out this article: http://weblogs.asp.net/rashid/archive/2010/07/10/use-razor-as-asp-net-mvc-viewengine.aspx
There are four things you need to do:
Add References to the Razor assemblies installed with WebMatrix. These can be found at C:\Program Files\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies
Create a custom ViewEngine class, a View class that inherits from IView (not that hard, check out the source in the article above)
Add your new ViewEngine in Global.asax Application_Start()
ViewEngines.Engines.Add(new RazorViewEngine(("cs"));
Create your view pages with a .cshtml extension, instead of .aspx
There are a few steps here, but it's quick work, and the source from the article above will get you a long way there.