.NETCore 常见错误 【2019-06-26 16:13更新】

.NETCore 常见错误

.NET

215 2018/8/2 13:38

An unhandled exception occurred while processing the request.

Microsoft.AspNetCore.Http.DefaultHttpContext.get_Session()

说明:Startup中未正确使用Session

解决:

  1. 安装Microsoft.AspNetCore.Session NuGet包

  2. 修改Startup.cs 添加相关服务,services.AddSession()和app.UseSession()【尤其注意,app.UseSession()必须要在app.UseMvc()之前】

Session 用法

引用

using Microsoft.AspNetCore.Http;

Session写入

HttpContext.Session.SetString("key", "value");

Session读取

HttpContext.Session.GetString("key");



上一篇 下一篇
music cover

歌曲名称

作者

00:00/00:00

歌名 歌手 时长