第十三节 身份认证

  1. 添加SettingController,如下图所示:

  1. Nop.Services.Configuration中的ISettingService.cs、SettingService.cs文件中添加InsertSetting(Setting setting, bool clearCache = true)方法的声明和定义。
  2. 添加LoginModel,如下图所示:

  1. 在Nop.Web项目中创建Setting文件夹中的Create.cshtml页面。

5按F5在手动生成MyNopCommerce数据库时,导航到Setting/Create页面,同时在页面提交数据时发现在数据库相应的表中出现相应的数据。

        6、重构Home文件夹中的Index.cshtml页面,使用ViewModel项目中的LoginModel为模型类。

        7、重构Controllers项目中的HomeController类,如图所示:

  1. 在Nop.Services项目中的Authentication文件夹中添加下列定义:CookieAuthenticationService.cs、IAuthenticationService.cs和NopAuthenticationDefaults.cs文件和类。
  2. 定义Nop.Web.Framework.Infrastructure.DependencyRegistrar类的Register方法中不回下列语句。

builder.RegisterType<CookieAuthenticationService>().As<IAuthenticationService>().InstancePerLifetimeScope();

10、按F5导航到home/index页面,同时提交登录数据时,在下列语句await _httpContextAccessor.HttpContext.SignInAsync(NopAuthenticationDefaults.AuthenticationScheme, userPrincipal, authenticationProperties);会出现异常:“No sign-in authentication handlers are registered. Did you forget to call AddAuthentication().AddCookies(Authentication) “

11、在Nop.Web.Framework.Infrastructure.Extensions.ServiceCollectionExtensions类中添加方法:

public static void AddNopAuthentication(this IServiceCollection services)

12、定义方法类:NopCookieDefaults.cs和IExternalAuthenticationRegistrar.cs如图所示:

13、在Nop.Web.Framework.Infrastructure.AuthenticationStartup类的ConfigureServices方法中添加语句:

//添加身份验证。

            services.AddNopAuthentication();

14、按F5导航到home/index页面,同时提交登录数据时, 页面会按照要求跳转到Setting/Create页面,同时已经解决第10步所出现的异常。

至于更新详细的信息请见我所上传代码“2019-10-17_MyNopCommerce_VS19Core2.2Nop4.20(不删,010_身份验证)。(https://download.csdn.net/download/zhoujian_911/11873625)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值