.net core MVC和WebApi使用Session的方法
在NETFW6.0 MVC框架中使用session添加两行代码即可。
builder.Services.AddSession(); app.UseSession();
在WebAPI框架中:
多加一行
builder.Services.AddDistributedMemoryCache(); builder.Services.AddSession(); builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); app.UseSession();
相关错误提示:
System.AggregateException:“Some services are not able to be constructed (Error while validating the service descriptor ‘ServiceType: Microsoft.AspNetCore.Session.ISessionStore Lifetime: Transient ImplementationType: Microsoft.AspNetCore.Session.DistributedSessionStore’: Unable to resolve service for type ‘Microsoft.Extensions.Caching.Distributed.IDistributedCache’ while attempting to activate ‘Microsoft.AspNetCore.Session.DistributedSessionStore’.)”
猜您可能还喜欢
- net core+webapi+nginx windows 服务器部署(1361)
- .Nuget Packages 太占C盘,删除后可以放到其他盘(1247)
- ASP.NET Core 配置 Swagger 显示接口注释描述信息(1142)
- vue调用接口后获取不到后端返回的Header响应头(1040)
- .net core 系列实例开发教程-权限管理系统功能介绍(992)
- .net core 6.0 web API + SwaggerUI + IIS部署(966)
- .net core 实例教程(十二)配置启用Swagger中的【Authorize】按钮(885)
- .net core 实例教程(一)新建项目(838)
- .net core 实例教程(十四)配置 Swagger 显示接口注释描述信息及支持版本控制(827)
- .net core 实例教程(十一)生成JWT格式的token密码配置及代码(803)
评论列表
发表评论
文章分类
文章归档
- 2025年3月 (1)
- 2024年6月 (2)
- 2024年5月 (2)
- 2024年4月 (4)
- 2024年3月 (30)
- 2024年1月 (4)
- 2023年12月 (2)
- 2023年11月 (4)
- 2023年10月 (4)
- 2023年9月 (6)
- 2023年3月 (2)
- 2023年2月 (1)
- 2023年1月 (1)
- 2022年12月 (1)
- 2022年9月 (21)
- 2022年8月 (10)
- 2022年7月 (3)
- 2022年4月 (1)
- 2022年3月 (13)
- 2021年8月 (1)
- 2021年3月 (1)
- 2020年12月 (42)
- 2020年11月 (7)
- 2020年10月 (5)
- 2020年8月 (1)
- 2020年6月 (1)
- 2020年3月 (2)
- 2019年12月 (8)
- 2019年11月 (3)
- 2019年9月 (1)
- 2019年4月 (1)
- 2019年3月 (6)
- 2019年2月 (1)
- 2018年7月 (7)
阅读排行
- 1.asp.net mvc内微信pc端、H5、JsApi支付方式总结(5751)
- 2.Windows 10休眠文件更改存储位置(3402)
- 3.各大搜索网站网站收录提交入口地址(3319)
- 4.ECharts仪表盘实例及参数使用详解(3219)
- 5.windows 10安装myeclipse 10破解补丁cracker.jar、run.bat闪退解决办法(3155)
- 6.HTML5 WebSocket与C#建立Socket连接实现代码(3015)
- 7.华为鸿蒙系统清除微信浏览器缓存方法(2926)
- 8.CERT_HAS_EXPIRED错误如何解决(2495)
- 9.Js异步async、await关键字详细介绍(lambda表达式中使用async和await关键字)(2343)
- 10.HBuilder编辑器格式化代码(2241)