In ASP.NET Core 6 Razor Pages how do I CRUD the Users and Roles? - razor-pages

I have followed this monumental tutorial Create an ASP.NET Core web app with user data protected by authorization which gave me a good oversight for Authorization.
However I still can't find a way to simply CRUD Roles and Users. Anywhere! The best I have seen are tutorials in MVC on making a list of users and roles. But that conflicts with my existing program.
There are a number of old tutorials, some still on the MS website, for MVC, webforms, etc, but nothing for Core 6 Razor pages.
Is there a CRUD of Core 6 ASPNetRoles and ASPNetUsers? If not why not? Is it a security issue? Does everyone roll their own? Is it so easy that I just don't get it?
Edit: As an update, I found this excellent resource https://github.com/mikebrind/Razor-Pages-In-Action/tree/main/Chapter10 if anyone else is looking for guidence.

They still exist, except much less is included in the template.
If you start with the .NET 6 Templates ex;
MVC - dotnet new web --auth individual
Razor Pages - dotnet new razor --auth individual
Blazor - dotnet new blazor --auth individual
It will kick you out a template with: Bootstrap CSS, Entity Framework and a database with the Identity Library and a Razor Class Library for the Register and sign in, etc.
From here, you are provided abstractions like IdentityUser, IdentityRole and base classes like RoleManager. There aren't any implementations or frontend code provided out of the box.
These abstractions give you the flexibility to opt-in, and tailor to suit your organizational requirements. CRUD is rather simple and will take very little effort to implement.
Reference Source for CRUD RoleManager in MVC -> https://github.com/procodeguide/Sample.Identity.Roles/blob/main/ProCodeGuide.Sample.Blog/Controllers/RoleController.cs

Related

Progressive web app with asp.net core 2.0 Razor Pages

I want to create a progressive web app with ASP.NET CORE 2.0 using Razor Pages preferably because I like the code behind architecture of Razor Pages.
Please recommend me a tutorial or docs or any course where I can begin to learn this. I already know ASP.NET CORE so I don't need to learn that, but actually I want to learn and create PWA but at server side I want to use ASP.NET CORE 2.0 and Razor Pages (if possible). And then I will be hosting them in Azure.
The courses I've searched so far on the web, all of them are with node.js or any other server side technology. Which is a problem because I don't want to use JS, except on the front end, where I don't have a choice.
According to your description, I assume that you could refer to the following tutorials for getting started with PWA using .NET Core:
Yeoman PWA Angular 4 & .NET Core
PWA-Asp.NetCore
Building Progressive Web Applications (PWA) with Visual Studio
This is a very common misconception...that the client-side is tightly coupled to the server-side. They are not.
Your ASP.NET application renders pages/html on demand, at run-time, on the server. The site will work with or without the client-side code, that is why it is progressive....
Your PWA/Service Worker code is only concerned with stuff in the browser. You need to think about it as a stateless concern on the client. The service worker can add a proxy layer to the client-side where you can cache and really perform the task ASP.NET or Node Or PHP, etc perform, just in the browser, before the network must be used.
My advice, to learn the concepts, is to create a static version of your site or a test site. Get comfortable with how to make a PWA and a simple caching service worker, then apply it to your ASP.NET site.
There is nothing in ASP.NET itself your service worker needs to know about, well short of your routes. And your routes are independent of ASP.NET.

Is it possible to combine DevExpress MVC Extensions with DexExtreme components in standard MVC application?

We should make a decision in our company what architecture to use in new web project. We've already successfully used DevExpress' WPF components and thinking of buying their web products, but don't have enough experience with them. So, the next question is for people who have some experience with DevExpress' web components.
Could we start the solution as standard MVC project built in VS 2013 and then add DevExpress' MVC extensions such as data grid etc. and DevExtreme components (jQuery or AngularJS) as well? If we can do that, could you explain, please, what could be possible difficulties?
I think it isn't a good idea to mix up server-side DevExpress Mvc Extensions and client-side DevExtreme Widgets. If you are comfortable with asp.net mvc and want to use client-side javascript technologies, look at DevExtreme Mvc Wrappers.
It supports a convenient razor syntax to configure widgets. And you can use javascript to handle events, implement client-side templates etc.
To see how it works in action, refer DevExtreme demos.

OWIN Katana, Webapi, MVC all in separate projects

I have a project that currently is using MVC5, WebApi2 and OWIN. It has become quite a bit larger than I anticipated and I am looking into splitting it up into separate projects. I will move the business logic and data access into a new project but then I was thinking about splitting the webapi and mvc into 2 more projects.
Really, there is very little MVC. Basically just the /index.cshtml and the /Help page. Everything else is Durandal. I was thinking if I were to move that out of the main project then then I would have some flexibility with hosting. It just seems that the MVC part of the application is heavy and not needed.
I would then make a webapi project, which is really where everything is happening anyway.
I have been considering using the OWIN pipeline and wrapping the webapi as middleware and the mvc project as middleware. Then I could have multiple startup classes that could be used for different configurations. One thing that I like about this idea is the webapi and the mcv app could be used individually or together. In either case, because of the nature of OWIN, it can be self hosted or run through IIS.
Now my question is...
Does this really make sense? There are potential cases for running the webapi service on its own. Are there any potential losses I will have to take in a setup like this?
Thanks.
#mnfact :- I would refer you to create two separate solutions one with the WebApi2,OWIN and another with the MVC5. It would be the good designing. Kindly go through the link :- " MVC & Web Api projects within same Solution "
I think there are can be issues while providing authentication to the WebApi and MNV5 project separately. Same for the datacontext you have to solve the Dependency between the controllers.
Hope this help you!

Converting ASP.NET MVC Project to ServiceStack.Razor

I have an existing ASP.NET MVC 4 project that already uses ServiceStack for REST services, and I just read all about ServiceStack.Razor and would love to move the entire project onto ServiceStack. Right now there is only one controller and view besides the built-in AccountController, and that controller just returns the view and the view is really just HTML; everything else is HTML/CSS/JS + ServiceStack REST.
The only real legacy constraint here is that this new app still needs to make use of SimpleMembership. At present I'm using a custom auth provider to authenticate against SimpleMembership and I would like to be able to continue to do so.
So, what would be the best recommended path to achieve this end? Can I get what I want by modifying my existing project by removing some references, or should I start fresh with an empty ASP.NET app and move the old stuff into it? Can I have SimpleMembership without introducing dependencies that will step all over ServiceStack.Razor?
If you were to start a new solution using only servicestack then MVC would never be there to get in the way.
I use servicestack.razor and love it. It is a lot simpler than MVC in my opinion. Moving everything to the new solution is pretty much going to be copy and paste since what you have works. I wouldn't hesitate and would make the move sooner than later. In the end you are not gaining anything from MVC. You only gain using servicestack. A big deal for me is self-hosting and eventually moving to mono.
This is a question that will have answers based off opinion so I suspect you will receive a few. I have not personally performed such a migration so this is only opinion but is how I would approach it. However, my recommended approach would be:
Retain the existing application/ Given its current simplicity, creating a new app and moving existing items into it seems unnecessary.
You should be able to use your existing auth solution via SimpleMembership and use ServiceStack.Razor. I would proceed as such however it does depend on what other ServiceStack features you may use which could cause conflict. A ServiceStack expert could comment more on this. Even if that did occur, you would be able to work around it relatively easy. At worst, implementing a simple handler would get around almost all issues from an authentication perspective.
Working with different razor engines is relatively easy to do and you can use/enable/disable existing or new build engines via a few lines of code. See here for an example. This should alleviate any concerns around dependencies of other built in or custom engines.
Consider looking at ASp.Net 4.5.1/VS 2013 (since your project is in early days) as it has enhanced membership support and is moving to a more "less dependent" model of components via the Owin stack Asp.Net 4.5.1 and VS 2013. Katana is a microsoft project that also provides some Owin based authentication components see here and here which you could use now and this would remove a lot of dependencies and enable you to migrate other framework with relative ease. Downside is that Katana/Owin has a little ramp up time/learning curve. Again, given your project is in its formative days I would recommend looking into Katana and the ASP.Net vNext stuff as this will make it easier for you and means you dont have to migrate to the new version once it is released.

Is there a yet fairly complete example projects servicestack that uses the new API?

I got the week off from work to learn servicestack and I am in awe of its simplicity, power, and speed.
I am a pluralsight subscriber and I am going through the Jon Somnez course which is great and as far as I can tell is using the new service stack api.
However, the examples in the pluralsight course are extremely simple and as such I am looking for a working example THAT USES the new API. I see that the wiki is up to date and that is very helpful...but I was hoping to find a working implementation that uses the new API and it seems that all of the examples I have downloaded or browsed are using the old API.
IS there a new working example/implementation (vs solution and projects.) that uses the new API yet?
If I can sneak in another question. Is there a recommendation (hopefully in the example project you can point me to) that explains a best practice for structuring your servicestack API project. (DTOs in a folder, services in a folder, response objects in a folder ??)
Thanks.
Update: ServiceStack Live Demo's and Examples are now being published on LiveDemos GitHub Project.
Most of the examples in ServiceStack.Examples has switched over to use the New API and are mostly available to demo on the servicestack.net homepage.
ServiceStack.UseCases contain a number of small single-purposed applications that are focused on how to enable specific features for different use-cases.
The SocialBootstrap API deployed at bootstrapapi.apphb.com is an example of an MVC and ServiceStack website together making with all the available authentication options together.
The Razor Rockstars is an example of a stand-alone ServiceStack application that demonstrates its website and HTML capabilities showing how you can add razor and markdown views to existing services to create a website that enhances existing services. There are 3 versions of Razor Rockstars available:
An ASP.NET Host
A Stand-alone Self-hosted using HttpListener
A Windows Service
Another website that's similar in spirit to Razor Rockstars is the Nortwind Database editor which demonstrates how you can enable a full-featured server-side HTML website to enhance your existing services. It includes a full-writeup of how he developed it and its capabilities on the accompanying blog post.

Resources