IHttpContextAccessor会话GetString

编程入门 行业动态 更新时间:2024-10-23 23:33:25
本文介绍了IHttpContextAccessor会话GetString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用.NET Core运行时将ASP.NET MVC站点迁移到ASP.NET Core.以前,我们可以使用

I'm trying to migrate an ASP.NET MVC site to ASP.NET Core with the .NET Core runtime. Previously we could get objects out of the session store, even in different assemblies, with

var obj = HttpContext.Current.Session[key]

现在我已经阅读了我们必须注入IHttpContextAccessor并在_contextAccessor.HttpContext.Session上使用该方法.但是Session对象的方法已更改,并且不再应用索引.

Now I've read we must inject IHttpContextAccessor and use the method on _contextAccessor.HttpContext.Session. But the methods of the Session object have changed, and it no longer has indexing applied.

我在使用HttpContext.Session.GetString()和HttpContext.Session.SetString()的其他问题中见过人们:

I have seen people in other questions using HttpContext.Session.GetString() and HttpContext.Session.SetString():

访问HttpContext.Current

有了这些,我至少可以反序列化要获取/获取的对象.但是我在界面上找不到这些方法.

With these I could at least de/serialize the object I want to fetch/get. But I can't find these methods on the interface.

"ISession"不包含"GetString"的定义,也没有扩展方法可以找到接受类型为"ISession"的第一个参数的"GetString"

'ISession' does not contain a definition for 'GetString' and no extension method 'GetString' accepting a first argument of type 'ISession' could be found

如何获得这些方法?

推荐答案

GetString 是 Microsoft.AspNetCore.Http.Extensions 程序集中的api/microsoft.aspnetcore.http.sessionextensions"rel =" noreferrer>扩展方法,请确保您对此有引用.您可能还需要导入它:

GetString is an extension method in the Microsoft.AspNetCore.Http.Extensions assembly, make sure you have a reference to that. You may also need to import it:

using Microsoft.AspNetCore.Http;

更多推荐

IHttpContextAccessor会话GetString

本文发布于:2023-11-10 06:25:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574601.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:IHttpContextAccessor   GetString

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!