Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 8th, 2004, 11:54 PM
Authorized User
Join Date: Aug 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get session values from a classes

I have a web application with C#.net.

I initialize session variable from a aspx web page (EX: Session.Add("city","New York").

After, I create a class .cs to get session variable value.

In my class : HttpSessionState ses = new HttpSessionState()

when I build.. show error: No overload for method 'HttpSessionState' takes '0' arguments.

I want to get sesion value in my class .cs, if my statement is wrong then you can help me ...in other way.

Why is it occur that? Could you help me? any other way?

Thank so much.
[email protected]
Old August 9th, 2004, 02:10 AM
Friend of Wrox
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post

HttpSessionState class doesn't have any default construcor use below
HttpSessionState ses
(without new)

Old August 9th, 2004, 08:39 AM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

Mehdi's suggestion is correct, but won't work:
A) It doesn't create an instance of the class
B) Even with an instance, all you have is a new (and empty) instance of the HttpSessionState class. It will have no meaning or context with the current page request, and therefore, no values in it.

In order for this to succeed you need to access the current session context.


This will get you the session object for the currently executing web request such that you can access actual session variables.
Old August 9th, 2004, 10:05 AM
Friend of Wrox
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post

surely this one line I told would not work it should be filled with a valid HttpSessionState object like Peter mentioned.(ses=System.Web.HttpContext.Current.Sess ion)
Thanks to Peter.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Session values to the Controls praveen.paspulate Classic ASP Basics 2 October 21st, 2008 10:43 AM
access values of a class in other classes keyvanjan ASP.NET 2.0 Professional 4 July 31st, 2007 11:27 AM
Session Variables in C# Classes rlb ASP.NET 2.0 Basics 3 April 5th, 2007 02:15 PM
delay in retrieving values through session mrjoka ASP.NET 2.0 Basics 2 March 14th, 2007 08:02 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.