且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有应用程序内商店的ASP.NET Core WebAPI项目个人用户帐户Visual Studio 2019

更新时间:2023-02-25 09:17:55

这是因为您已选择API项目模板,并试图在该模板上设置Individual User Accounts模式,但WebAPI模板没有Store user account in-app功能.>

如果您正在使用MVC项目,并尝试将身份验证模式设置为个人用户帐户",则会看到Store user accounts in-app选项.

此外,您可以尝试使用控制台中的命令来启动项目,如此答案中所述:>

dotnet new webapi -au Individual

之后,您可以在VS中打开您的项目. (围绕 对话).然后,您可以使用例如authorize-attribute.但是 项目仍配置为使用Azure承载身份验证.你 必须决定从哪里获得身份.你可以采取 identityserver4或构建自己的自定义存储提供商" ASP.NET核心标识"( MS文档)

这是因为在MVC项目中,您有一个帐户控制者, 视图以处理注册并获取用户名和密码等 第四,但是WebAPI中没有这样的东西,您必须使用其他 JWT之类的身份验证机制.

AspNetCore的Github中对此功能进行了讨论.

I was trying to create a project in visual studio, I chose the option Individual User Account after selecting WebApi project, and now in VS 2019 it seems to be pretty different than before, now some parameters are requested, can anybody give me some examples of how to configure it?

It is asking about:

Domain Name
Application ID
Sign-up or Sign-in Policy

And by default it is selected like the only option to select:

Connect to an existing user store in the cloud

That's because you are selected API project template and trying to set Individual User Accounts mode on that but WebAPI templates don't have the Store user account in-app feature.

If you're using MVC project and try to set the Authentication mode to Individual User Accounts you'll see the Store user accounts in-app option.

Also, you can try to start your project in the console with this command as said in this answer:

dotnet new webapi -au Individual

You can open your project in VS after that. (to work around the dialog). Then you can use for example the authorize-attribute. But the project is still configured to use Azure Bearer Authentication. You have to decide where to get identity from. You can take identityserver4 or build your own "Custom storage providers for ASP.NET Core Identity" (MS-Docs)

This is because in MVC projects you have an account controller with views to handle registrations and get a username and password and so forth, but there's no such a thing in WebAPI and you have to use other authentication mechanisms like JWT.

There's a discussion about this feature in AspNetCore's Github.