使用HttpContext从类库中删除当前会话

时间:2023-01-15 15:50:55

Remove HttpContext.Current.Session

删除HttpContext.Current.Session

HttpContext.Current.Session.Clear();
HttpContext.Current.Session.Abandon();

Does this have the same effect as

这是否具有相同的效果

Session.Clear();
Session.Abandon();

HttpContext.Current.Session.Clear() and .Abandon() is not removing the current session when called from from a Class library.

从类库调用时,HttpContext.Current.Session.Clear()和.Abandon()不会删除当前会话。

1 个解决方案

#1


0  

They are the same thing the only major difference is that the getter for Page.Session returns the context session. I will quote the MSDN article here

它们是唯一的主要区别是Page.Session的getter返回上下文会话。我将在这里引用MSDN文章

This property is a static property of the HttpContext class. The property stores the HttpContext instance that applies to the current request. The properties of this instance are the non-static properties of the HttpContext class. You can also use the Page.Context property to access the HttpContext object for the current HTTP request.

此属性是HttpContext类的静态属性。该属性存储应用于当前请求的HttpContext实例。此实例的属性是HttpContext类的非静态属性。您还可以使用Page.Context属性来访问当前HTTP请求的HttpContext对象。

You can find more information here and here.

您可以在此处和此处找到更多信息。

#1


0  

They are the same thing the only major difference is that the getter for Page.Session returns the context session. I will quote the MSDN article here

它们是唯一的主要区别是Page.Session的getter返回上下文会话。我将在这里引用MSDN文章

This property is a static property of the HttpContext class. The property stores the HttpContext instance that applies to the current request. The properties of this instance are the non-static properties of the HttpContext class. You can also use the Page.Context property to access the HttpContext object for the current HTTP request.

此属性是HttpContext类的静态属性。该属性存储应用于当前请求的HttpContext实例。此实例的属性是HttpContext类的非静态属性。您还可以使用Page.Context属性来访问当前HTTP请求的HttpContext对象。

You can find more information here and here.

您可以在此处和此处找到更多信息。