.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

Storing TcpClient object in session

Posted By:      Posted Date: October 18, 2010    Points: 0   Category :ASP.Net


I am experimenting with an asp.net application wherein I do the following things (simplified for the purpose of this discussion):

1. Take user's gmail username/password (don't fret, I am not doing any nasty stuff Wink).

2. Create TcpClient object and connect it to the Gmail's POP email server using the provided username/password.

3. I am going to use this TcpClient object to download mails for the user.

Following is the problem I face:

1. Say I have presented the user with the subject lines of all his emails.

2. Now he clicks one subject line to download the message. (This will create the post-back to the aspx page)

3. When I receive the post back, will I be able to re-use the same TcpClient object which I connected to the POP server, if I store that object as a Session variable?

I doubt the streams associated with the object will not remain valid.

Is this even the right method to achieve what I am trying to achieve?



View Complete Post

More Related Resource Links

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

storing Session in sql server?



I want to show all the activities of the logged in user in a gridview. I am using VS 2010. please suggest some good ways of doing it.



session object security in asp.net 4

hi,So I'm developing a complicated solution where users need to register, on the web application. I'm not going to use asp.net forms authentication because it would be too complicated to make it work in my app. We do not have SSL, it doesnt need to be super secure but the only thing I am worried about is:When the user logins, he is authenticated, then his username is stored in an asp.net session object. Every protected page then check if there is a username, is there isn't he is redirected. Is this secure?Is there a way an attacker can manipulate a session object to have it store a valid username, which will fool the pages to think that user has logged in. Is there any way to make it slightly more secure without hitting too much on performance?All the options I see are all about forms authentication.Thanks so much

Session Object not set to an instance.....

Hello all, Please tell me if I have made a mistake in the following code. It is part of a class that cycles through various conditions to return a value to aspx page. I get null exception when it hits the session variable. I even declared the session variable in global.asax, and thought that I was checking for null value correctly. Obviously I haven'tImports Microsoft.VisualBasic Imports System.Linq Imports System.Web Imports System.Web.Services Imports System.Web.HttpContext Public Class OrderNumber Public Shared Function GetOrderNumber() As String ' ''//Sets OrderNumber if it exists If Not HttpContext.Current.Request.QueryString("OrderNumber") Is Nothing Then Return CType(HttpContext.Current.Request.QueryString("OrderNumber"), String) ElseIf Not HttpContext.Current.Session("OrderNumber") Is Nothing Then Return CType(HttpContext.Current.Session("OrderNumber"), String) ElseIf Not FindExistingOrder() Is Nothing Then Return FindExistingOrder() Else : Return "" End If End Function   Thanks, I am pretty well stumped. Have a good evening.

WCF using ASP .NET Session and Timer object

I've got a WCF service that handles account management for a Silverlight 4 application. It uses PerSession as the InstanceContextMode and Required as the AspNetCompatibilityRequirementsMode so I can use ASP .NET SessionState (Silverlight only supports BasicHttpBinding, which doesn't support WCF sessions). When the client application calls the Login method, the service sets up a System.Timers.Timer object that fires after five minutes. The client calls a KeepAlive method every thirty seconds to let the service know its still alive, KeepAlive resets the timer. The idea is if the user leaves by closing the browser or leaving the page without properly logging out, after five minutes the timer event fires and it's supposed to set some flags in the application's database. This mostly works. The problem is that HttpContext.Current.Session is always null within the timer event. It works fine within the other methods. Since I can't access session, I can't figure out which user it is to perform cleanup. Can I access the Session object? Is there a better way for me to maintain session state while keeping Silverlight compatibility?

Storing large data in Session State

Hi, We have a scenario where we need to store large tables of data on Session in asp.net page. on a highlevel we have to store following data  1> A table (table 1) with 1000 rows and 8 to 10 columns. 2> A table(table 2) with 500 rows and 8 to 10 columns (actually user can add the data from table 1 to table 2, so as user keeps on adding from table 1 we remove the data and put it in table 2) 3> Another table(table 3) with 1000-1200 rows each having 3 columns. We are having a webfarm, so we need to store it in either SateServer of Oracle DB, please advise which one is better. What would be the performance implications of storing such huge data on the server. One more thing is at any point of time max of 70 -80 people will be accessing our website, so will this cause any performance degradation? Thanks in anticipation Harsha

Weird casting error (storing Generic list in Session)


Am trying to store a generic list in Session to act as a simple shopping cart. Am getting a weird casting error when I try and retrieve it from Session.

A critical error has occurred.
[A]System.Collections.Generic.List`1[MyCartItem] cannot be cast to [B]System.Collections.Generic.List`1[MyCartItem].
Type A originates from 'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    in the context 'LoadNeither' at location 'C:\WINDOWS\assembly\GAC_32\mscorlib\\mscorlib.dll'.
Type B originates from 'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    in the context 'LoadNeither' at location 'C:\WINDOWS\assembly\GAC_32\mscorlib\\mscorlib.dll'.

I have a class variable defined:

List<MyCartItem> _cart;

In the Load event I have:

_cart = (Session["MyCart"] != null) ? (List<MyCartItem>)Session["MyCart"] : new List<MyCartItem>();

page inside update panel doesn't refresh the session object after postback of any control



I have many controls like dropdown, radiobuttonlist, etc on my page and I put all these controls inside the update panel so that the page doesn't look to be posting back when something is selected. Now the working on the page is very smooth. But the session object isn't getting refreshed even if I postback to the server and as a result even if the users are working on the page they are being sent to the login screen after 20 mins.

Is there anyway where I could put all the controls in update panel and still refresh the session after any postback(dropdown selection)

Any help is greatly appreciated.

Thanks in advance

Keep updating Session object with a new List c#


I have a Session object

Session["MyListObjects"] = null;

When a user hits a button I want to creat a List<string> object and add to session object.

Let's say if user hits the button 10 times, I would get 10 List<string> objects and
add to Session["MyListObjects"] and

Finally I want to read all the List<string> objects from the session object.

Please let me know how to do that.

How can I manage session data outside the ASP.Net session object?


I want to be able to persist data across a session but do this outside of the built-in session state object.  Why is a long story that I will not go into here.  I just need to know where I can put data other than in the session object that will persist across the specific session (in memory - I already have a database solotion).


Session variable, Gridview paging and Storing the ID HELP




I have a gridview and a checkbox. I am able to pass the checkbox id to a textbox in the same page. This is then passed as a session variable. However, when I place an option to page and select the checkbox items in the next page, the session variable resets.

Please see below code, how do I store "all checkbox" throughout all paging and store it in the session page?


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            BorderStyle="Solid"    CellPadding="4" DataKeyNames="Categoryid" 
            BorderColor="Silver" BorderWidth="1px"    Width="300px" 
            DataSourceID="SqlDataSource1" AllowPaging=

Storing session data continuouly




Is it possible to store gridview session data after each postback. I have a gridview and a checkbox within. Each time a user clicks the checkbox, I like to store the gridview ID in a session. After browsing through various pages, I like this session data to continuously store the information up to 20mins?


How can I continously store the session variable. Please can someone provide a sample? Say a text box and if I enter 1 click on a hyperlink (where session variable is stored) return back to the page, enter 2 click hyperlink then I should get in the session 12?

Any one know how to do this? Please provide code in VB.

THanks! Nijojo

Session time-out : object reference not set to an instance...


I noticed that when i am debugging my web application in Visual Studio 2005 using IIS, after about 10-15 minutes of inactivity, when I do something in the application such as a postback, I get an immediate error saying: "object reference not set to an instance" and my code breaks somewhere.

Is my assumption correct that this is because my session has timed out? ( i do have a 15 minute default session time)

my next question is, how do I display or set a way so that like many other pages, when the session has expired, a message will say: "This page must be refreshed" or "Your session has expired, click okay to refresh page" and start over again?


Storing search keyword in Session variable


Hello gurus,

I have heard alot about sql injection and how it is normally caused. Mostly sql injection in my opinion is caused through search boxes. Now my question is quite simple. Is it advisable to store the search keyword in a session variable to prevent sql injection? I don't want to expose the keyword through the querystring as it is prone to attacks. So in short there is no harm in using session variables to store the keyword right?


storing Datatable in Session variable


I am storing Datatable in Session variable in my project. Is it good practise to do so? The datatable has 20 fields and can run into 1000+ records. Will it hamper my application performance? If yes then can anyone suggest better alternative.

Access property of object as session variable as declarative datasource parameter value


I am storing a custom "Organisation" object as a session variable. One of the properties of  the Organisation object is "OrganisationID" (integer).

I have a DataSource that requires a parameter value to run, and I want to use a SessionParameter to populate this. In a previous version, I stored the OrganisationID directly as a session variable. In that case, I could easily access it like this:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    SelectCommand="spGetUserJobList" SelectCommandType="StoredProcedure">
        <asp:SessionParameter Name="OrganisationID" SessionField="OrganisationID" Type="Int32" />

However, how do I now access the OrganisationID property of an "Organisation" type session variable (called "Organisation")?

 I have tried this, which does not seem to work:

<asp:SessionParameter Name="OrganisationID" SessionField="Organisation.OrganisationID" Type="Int32" />


Is there a way to access the Session object during the Session_End event?


I've tried, but all of my Session variables are coming up as Nothing when the Session_End event is run.  I'm trying to update log files to reflect that a session either timed out or was abandoned, but I'm not having any luck.  Has anyone else done something like this before?  If so, how?  At the very least, I'd like to be able to log the SessionID.

Suggestions are welcome!

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