没有用于ASP.NET Core 2.1的AccountController [英] No AccountController for asp.net core 2.1

查看:47
本文介绍了没有用于ASP.NET Core 2.1的AccountController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到在asp.net核心2.1中,身份已经改变,但是如果将它们作为支架添加到解决方案中,则可以将其添加到解决方案中.

它为所有页面添加了所有剃刀类库.

但是我想做的是使用旧的AccountController方法,客户端(移动或网络)可以将其发布到与帐户相关的API..

我有什么办法可以恢复原来的状态或类似的方法.这样我就可以使用来自客户端的api

解决方案

不幸的是,它不再存在.我个人对这一变化以及团队不断向所有人推销Razor Pages感到非常恼怒,坦白地说,这些信息应该留在历史的垃圾箱中.

我个人所做的就是添加脚手架,然后创建我自己的控制器,将Razor Pages代码改编并将其重写为传统的MVC样式的控制器和视图.虽然这不是一个愉快的经历,但是我不知道有没有其他办法可以通过这种方式获得.

但是要注意的一件事是, AddDefaultIdentity 扩展实际上也添加了默认的UI,就像将其脚手架插入到项目中一样.换句话说,即使您将所有内容移至控制器和视图并删除所有脚手架的东西,剃刀页面"路线也将 still 置于优先位置.更不幸的是,没有 good 替代品来添加 AddDefaultIdentity .相反,这是您需要的:

  services.AddIdentityCore< ApplicationUser>(o =>{//身份配置}).AddSignInManager().AddDefaultTokenProviders().AddEntityFrameworkStores< YourContext>();services.ConfigureApplicationCookie(o =>{o.LoginPath ="/signin";o.LogoutPath ="/signout";o.AccessDeniedPath ="/signin";o.ReturnUrlParameter ="returnUrl";}); 

很显然,最后,您需要将URL更改为自己的应用程序路由.

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

解决方案

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.

这篇关于没有用于ASP.NET Core 2.1的AccountController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆