.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Session or Request in class without passing as param

Posted By:      Posted Date: September 04, 2010    Points: 0   Category :ASP.Net
I'd like to be able to reference the asp.net objects Session, Request, from a procedure without passing them in as parameters all the time. Is there a way to do this. For example, now I have namespace xx { public class ContextPT { public static string GetSession(System.Web.SessionState.HttpSessionState inSession) { StringBuilder sb = new StringBuilder(1000); string nameType; string value; foreach (string s in inSession.Keys) { nameType = s + " " + inSession[s].GetType().ToString(); value = inSession[s].ToString(); sb.AppendLine(nameType + ": " + value); // dataRow(new string[] {nameType, value}); } return sb.ToString(); } } } somewhere else this.lContext.Text = ContextPT.GetSession(Session); I'd like to call it like this "ContextPT.GetSession()" and have GetSession know how to find the Session object.  I know this does not seem like a big deal in this case, but I have reasons. 

View Complete Post

More Related Resource Links

How to implement custom HttpContext for each request under class that implements IHTTPHandler


Hello All,

I created an application and implemented IHTTPHandler for all incoming request ending with ".aspx" extension.

Under "ProcessRequest" module, I am creating an instance of HttpContext (with URL attributes different from my application's URL i.e. if I am working on localhost then speciying Yahoo.com as its URL) and assigning it to "context" which comes as method argument.

After redirection, an error is generated. Also, the custom HTTPContext is not passed to the requested page (default.aspx, in my case.)

Code is as follows.

    Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
            Dim requestedUrl As String
            Dim targetUrl As String
            Dim urlLength As Integer
            'Save settings which will be used while redirecting to appropriate page
            requestedUrl = context.Request.RawUrl
            If requestedUrl.IndexOf("?") >= 0 Then
                targetUrl = requestedUrl.Substring(0, requestedUrl.IndexOf("?"))
                targetUrl = requestedUrl
            End If
            If targetUrl = Nothing Or targetUrl.Length = 0 Then
                targetUrl = requestedUrl
            End If

passing page title through a param


Hello all,

   I am new to ASP.NET, and was wondering how to pass a Page title through a parameter.  In classic ASP I could just use something like: <title><%=Pagetitle%></title> but I cannot seem to get this to work in ASP.NET. 

Thank you in advance,

The New Guy... Smile 

send data in class object from one page to another using session


hello everybody

now i hav stored all data like user name, data fatched from database of that user

and i stored that data and user name such as:

string strUserName="user name"

dataset ds =new dataset();// data of that user

now i wan yo send d whole data from my login page to user profile page

can anybody help me for that...................

and plz tell me that how much is this way is benifitial to send data from one page to another page

plz........kindly waiting for positive rply

Good news for those of you who get "Unable to make the session state request to the session state se


Dear all,

Due to the known problem of session variables getting lost if using InProc-server during frequent changes in development, I had to choose between SQL and ASP.NET State server, so I opted for the second. Initially, all fine, but after using it for a few days, I started to get this error:

 Server Error in '/cv2' Application.
Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same.  If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection.  If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either 'localhost' or '' as the server name.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the clie

Setting a session variable OR passing along information in Javascript

Hello, Form1 needs to send information to Form 2. Form2  opens in it's own window and is sized smaller. I need to send information to Form2 in order to set parameters in the query in Form2. At first I was just going to use an asp button control and load up some session variables, then I remembered that in order to have the next screen (Form2) open in its own window and be able to size it, I had to use an input type="Button" and use Javascript to open the new window like this:<script type="text/javascript"> function open_win() { window.open("/Accounts/Form2.aspx","_blank","toolbar=no, location=yes, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=1000, height=500"); } </script> But by doing this, I don't know how to pass the information along I need for Form2. How can I pass variable information to Form2?  The data comes from two textboxes on Form1: txtStartDate and txtEndDate. Thank you. 

Retriving data from CheckBoxList and passing it to a Session



I wondering how can I retrive data from a CheckBoxList in c#. and once I get the data I would like to store the data in a session so I can use the data from a session on a another page

Thank you in advance

which library or class should be included while using "Session"


hi guys,

i want to use session to store some information for a form(ascx and ascx.cs file)

im using asp.net, c#, and visual studio 2005 , i included  "using System.Web.SessionState;" but session is not a key word in visual studio intellisense. and also, i researched a little and found that many people are using

"using System.Web.SessionState.HttpSessionState;"  and the HttpSessionState is not in the intellisense as well...

so which other classes or libraries should i using in order to use session?

IIS 6.0 not passing request to asp.net



 I have my asp.net mvc site set up with wildcard mapping. for requests that dont have a matching routing, IIS6.0 is showing the default 404 error message even though i have customerror message configured in the web.config. 

Any ideas?

HttpContext.Session A potentially dangerous Request.QueryString value was detected from the client


I have an ashx handler that was working fine in VS2008 but when I upgraded to VS2010 (haven't gone back to VS2008 to double check though) and when I try to grab the value from HttpContext.Request.Params["update"] I get the following error:

+ ex {"A potentially dangerous Request.QueryString value was detected from the client (update=\"<SETIProducts><Produ...\")."} System.Exception {System.Web.HttpRequestValidationException}

"A potentially dangerous Request.QueryString value was detected from the client (update=\"<SETIProducts><Produ...\")."} System.Exception {System.Web.HttpRequestValidationException}

I've read that I can set the validateRequest to false, but I was wondering about the impacts and looking for any other suggestions. 

I know very little about security when it comes to web programming but I thought I should mention that my handler will be running on a internal file server but transmitting data to/from an eCommerce platfo

Passing variables in a post request


Hi I need to pass variables from a script to another with POST , Not GET , and without a form ( i must do it literally )

there is the Response.AddHeader(name,value) function

then the response.redirect

But then i think the variable field has no name ( after the content lenght header ).

Any ideas how to do this ? thanks


edit : typo corrected

Passing ViewModel (containing request parameters) across controllers


Pls. pardon my ignorance. I have few questions based on following scenario:

I have a LoginController with following methods:

 public ActionResult Login()
        return View();

    public ActionResult Login(UserObject user)
     Calling Besiness Service to Validate User againts DB (Using Repository)... 

        if (success)
            return RedirectToAction("Search", "Search");
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
        return View(user);

After successful login, I have to present a Search screen. I have a SearchController with following methods:


Session in a Class in a Thread



I'm starting a new thread with:

Dim Thread_Connect As New Threading.Thread(AddressOf Thread_ConnectCustomerToDebitor)


In the thread I can acces the session values with:


But i need the session values in a class. There i got the error "Session is not declared". Usually i can access the session with:


But in the new thread is HttpContext.Current=Nothing

How can I access the session values inside the class?

Can I Assign class object to session variable?


Hi all, i have a class Emp and whether it is possible to save the object of this class in a session?

And after creating the session with object how can i store it in state service and how can i use the object from session??

thanks in advance...

redirect asp.net website having Sessions from localhost by passing the session values


hi friends

             I want to open a web site in code by giving the server url, but in that server page we are restricting if session is null. Is work the session passing from the localhost in server???

How to pass session from local host to server



Passing service end point credential in request

I need to call a service end point protected behind a security gateway (non-ms technology from IBM), so there are credentials for the gateway and credentials for the service end points, how can I pass these two sets of credential in the service call?

StackOverflowException was unhandled when passing in DataContract class


Hi guys, i'm new to WFC and I'm experiencing a problem when I pass my DataContract class:

    public class FileAttachment
        private byte[] binaryBuffer = null;
        private String FileName = string.Empty;

        public byte[] FileBufferByteArray
            get { return binaryBuffer; }
            set { binaryBuffer = value; }

        public string FileAttachmentName
            get { return FileAttachmentName; }
            set { FileAttachmentName = value; }


into the service. I'm constantly getting a System.StackOverflowE

Passing class by value - Remoting



For a class like following,

 public class SampleClass 
  public String Name { get; set; }

and a class Library containing following void method which simply assigns some value to the property.

public void AssignValueToClass(SampleClass classInstance)<br/>{
 classInstance.Name = "Name assigned to Class";

When I call above method through Remoting client like following


RemotingClient client = MyRemoteObject.GetClient();
SampleClass instance = new SampleClas();
MessageBox.Show(instance.Name); -- No Value is assigned to the class, Value of Name remains Null and message box shows empty.


But when I simply add a reference to my class library, and simple create the instance of the cl

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend