Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No AccountController for asp.net core 2.1

I realise in asp.net core 2.1 Identity has been shifted, but can be added to the solution if you add them as a scaffolded item.

It adds all the razor class library for all the pages.

However what I want to do is have the old AccountController way where a client (mobile or web) can post to the account related API's..

What are my options for being able to get the old way back or similar. so that i can use api's from clients

like image 812
raklos Avatar asked Jul 02 '18 14:07

raklos


1 Answers

Unfortunately, it doesn't exist any more. I was personally very aggravated by this change, as well as the team's endless pushing of Razor Pages on everyone, which frankly should have been left in the dustbin of history </rant>.

What I have done, personally, is add the scaffold, and then create my own controllers, shuffling and rewriting the Razor Pages code into traditional MVC-style controllers and views. This was not a pleasant experience, though, but I know of no other way if you want it this way.

One thing to note, though, is that the AddDefaultIdentity extension actually adds the default UI, as well, just as if you had scaffolded it into your project. In other words, even if you move everything over to controllers and views and delete all the scaffolded stuff, the Razor Pages routes will still take precedence. Even more unfortunate, there's no good alternative to add AddDefaultIdentity. This is what you'll need instead:

services.AddIdentityCore<ApplicationUser>(o =>
{
    // Identity config
})
.AddSignInManager()
.AddDefaultTokenProviders()
.AddEntityFrameworkStores<YourContext>();

services.ConfigureApplicationCookie(o =>
{
    o.LoginPath = "/signin";
    o.LogoutPath = "/signout";
    o.AccessDeniedPath = "/signin";
    o.ReturnUrlParameter = "returnUrl";
});

Obviously, in the last bit, you'd change the URLs to your own applications routes.

like image 108
Chris Pratt Avatar answered Jan 01 '23 21:01

Chris Pratt