API 程序的认证过程:
- 编写api程序
- 在startup.cs中的configureServices中添加services.AddAuthentication(IISDefaults.AuthenticationScheme)
- 在launchSettings.json中将 :"windowsAuthentication": true, "anonymousAuthentication": true,
- 在controller中将函数的使用认证注解: [Authorize(Roles = @"care")] 其中的角色是在域环境中给您分配的组
- 配置域环境,在局域网中运行,要将自己服务器的DNS改成域环境的DNS
- 将自己在域环境中进行分组,对应4中的Roles
- 开启本地的IIS,在控制面板中:程序和功能中-》打开或关闭windows功能-》将INternet信息服务全选上,之后等待安装
- 之后将编写的工程发布到IIs的inetpub->wwwroot中,将发布的东西放在其中就好
注意:
- 在本地显示域环境相关信息和分组状况的命令:在cmd中输入:gpresult /V
- window认证的获得其中用户的名字和相关的id的命令: System.Security.Principal.WindowsIdentity.GetCurrent()