在 ASP.NET 的公共类中使用会话状态?
我正在尝试将一些可重用的代码部分移到一个类中。除非我尝试在此类中使用 Session ,否则这工作正常。我收到错误:
“如果没有类的显式实例,则无法从共享方法或共享成员初始值设定项中引用类的实例成员。”
我的代码看起来像这样:
Public Class webHousing
Inherits System.Web.UI.Page
Public Sub GetUserInfo()
Dim x as String
x = 10
Session("x")= x
End Sub
End Class
我已经显着简化了此代码 - 但存在基本问题 - 尝试从类内设置会话值。我找到了以下 MSDN 文章1 但不相信 Public/ Shared可以用在Session上吗?
I'm trying to move some reusable portions of code into a class. This is working okay except when I attempt to use Session within this class. I get an error:
"Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class."
My code looks something like this:
Public Class webHousing
Inherits System.Web.UI.Page
Public Sub GetUserInfo()
Dim x as String
x = 10
Session("x")= x
End Sub
End Class
I've simplified this code significantly - but the basic problem is present - trying to set a session value from within a class. I found the following MSDN article1 but don't believe Public/Shared can be used on Session?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
Try