Showing posts with label object. Show all posts
Showing posts with label object. Show all posts

Saturday, March 31, 2012

Session timing problem

in ASP.NET 1.1, I want to keep my session alive for a while.

I add an object to session (Session.Add()) and set the session timeout in the web.config for 20 minutes however it seems to lose the session after 5 minutes (well before 20 minutes) or after a few refreshes of the page.

any ideas how I can keep the session alive for longer fully until the time specified in the web.config?Might be a problem with the ASP.NET worker process. Check your Event Viewer first to see if W3WP or any related processes have errored out, which may be causing the worker process to recycle (therefore ending the session)
i doubt that is the issue as the same problem happens when i upload it to my web hosting server. :)

Thursday, March 29, 2012

session varaibles with asp.net urgent help

hi i store some value in session object and later try to access it but the
value return from session variable is null
like
Session["Myname"]=txtmyname.Text;
Session["Age"]=txtAge.Text;
Response.Redirect("Welcome.aspx");
when this page loaded and iin page load event i called
lblMyname.Text=(string)session["Myname"];
lblAge.Text=(string)session["Age"];
it return null value instead of actual values.
i tried to store session value both in sql database and local memory both
result are sameamjad wrote:

Quote:

Originally Posted by

hi i store some value in session object and later try to access it but the
value return from session variable is null
like
Session["Myname"]=txtmyname.Text;
Session["Age"]=txtAge.Text;
Response.Redirect("Welcome.aspx");
when this page loaded and iin page load event i called
lblMyname.Text=(string)session["Myname"];
lblAge.Text=(string)session["Age"];
it return null value instead of actual values.
i tried to store session value both in sql database and local memory both
result are same


The possible chances are these:
1. you have started session somewhere else (on anyother page) as well
and
session is not abondened yet (with session.abonden).

2.

Quote:

Originally Posted by

lblMyname.Text=(string)session["Myname"]; //session's s should be capital i.e Session


3. or try this instead

lblMyname.Text=Session["email"].ToString();
3.
lblAge.Text=Session["Age"].ToString()
its not the Session i wrote small otherwise c # cannot compile. . i have
cancelled the session variable but still cannt display that value in another
page.

"nasirmajor@.yahoo.com" wrote:

Quote:

Originally Posted by

>
amjad wrote:

Quote:

Originally Posted by

hi i store some value in session object and later try to access it but the
value return from session variable is null
like
Session["Myname"]=txtmyname.Text;
Session["Age"]=txtAge.Text;
Response.Redirect("Welcome.aspx");
when this page loaded and iin page load event i called
lblMyname.Text=(string)session["Myname"];
lblAge.Text=(string)session["Age"];
it return null value instead of actual values.
i tried to store session value both in sql database and local memory both
result are same


>
The possible chances are these:
1. you have started session somewhere else (on anyother page) as well
and
session is not abondened yet (with session.abonden).
>
2.

Quote:

Originally Posted by

lblMyname.Text=(string)session["Myname"]; //session's s should be capital i.e Session


>
>
3. or try this instead
>
lblMyname.Text=Session["email"].ToString();
>
>


where have you cancelled/cleared the session?
when i do that instead of (string)Session["Age"] then it gave me that error
System.NullReferenceException: Object reference not set to an instance of an
object.

"nasirmajor@.yahoo.com" wrote:

Quote:

Originally Posted by

>
3.
lblAge.Text=Session["Age"].ToString()
>
>


amjad wrote:

Quote:

Originally Posted by

when i do that instead of (string)Session["Age"] then it gave me that error
System.NullReferenceException: Object reference not set to an instance of an
object.
>
>
"nasirmajor@.yahoo.com" wrote:
>

Quote:

Originally Posted by


3.
lblAge.Text=Session["Age"].ToString()


where ever if you have used session.clear or session.removeall replace
it with
session.abondon();
try whats happen?

Session variable

Hello,
How to declare a variable of session without value (empty) ?
Because If I use a page with a Null Session I have the error :
"Object reference not set to an instance of an object."
on this line :
Line 16: Dim SessionUser As String = Session("USER").ToString

Thank you for your help.
PAB.You can use String.Empty for string values
Hello,
Thanks, I try that.
PAB.
C#

if ( Session["User"] == null)
{

// not exists

}

VB.Net

IF SESSION["USER"] is Nothing THEN

// Not Exists.

END IF

Monday, March 26, 2012

session variable or object

i have some problem with session object:

for example if i define a session variable
and make it equal to a string(i.e session("str")="fgjfkg" )
when i want to use it in another page it's value is equal with nothing
(i.e session("str")=nothing)
is you know how to solve prolem please tell me

thanksHello, make sure session are enabled in the asp.net application you have. Check your web.config file.
Also, make sure that cookies are enabled on ur machine, since sessions will use cookies.

regards.
hi

thanks for your suggestion,i try it but it didn,t
solve my problem again the session variable couldn't
store any value i have a question is it neccesary to use it
in "session start" in clobal.asax

regards
A.Doroudian
Hello, yes you should, you have to inclide the Session_Onstart method.

regards.

Saturday, March 24, 2012

Session variable problem

I have a Session object set on Session_Start...
I figured out that the object is never created...
Cannot understand why..

Also I noticed that the debugger will not stop at
breakpoints that are inside the Session_Start method or in
the class of the object that is created within the
Session_Start method...

Is this a bug or a setting problem?
any ideas?I think you might be misunderstanding the message.
The message is probably referring to the Session object
being nothing, not the content.

Session will never bomb out on an object being nothing in
the context you show. Session will be nothing in any
classes you create. Instead,
use "Current.Session.item..." and you should be able to
get your object just fine.

It helps to put a reference to:
System.Web.HttpContext
in your "Imports" in the project properties under the
properties page, Common Properties folder. Otherwise you
need to reference System.Web.HttpContext.Current.Session

Email if you need more...
>--Original Message--
>Ok...
>in Global.asax I have:
>protected void Session_Start(Object sender, EventArgs e)
>{
>cms.errorHandler error = new cms.errorHandler();
>Session["error"] = error;
>}
>and then in my code I have:
>errorHandler error = (errorHandler)Session["error"];
>I get:
>Object Reference not set to an instance of an object
>(NullReferenceException).
>I even get the Exception if I do:
>Session["test"] = "Test";
>Yes I debug the application
>.
I dont understand where to put the reference of
System.Web.HttpContext to. Is there such thing? On my
project properties page there no such thing as "Imports"
under Common Properties. I couldnt find anything like that.
Even in the code if I do "using System.Web." there is not
HttpContext...

Am I missing something here?

>--Original Message--
>I think you might be misunderstanding the message.
>The message is probably referring to the Session object
>being nothing, not the content.
>Session will never bomb out on an object being nothing in
>the context you show. Session will be nothing in any
>classes you create. Instead,
>use "Current.Session.item..." and you should be able to
>get your object just fine.
>It helps to put a reference to:
>System.Web.HttpContext
>in your "Imports" in the project properties under the
>properties page, Common Properties folder. Otherwise you
>need to reference System.Web.HttpContext.Current.Session
>Email if you need more...
>>--Original Message--
>>Ok...
>>
>>in Global.asax I have:
>>
>>protected void Session_Start(Object sender, EventArgs e)
>>{
>>cms.errorHandler error = new cms.errorHandler();
>>Session["error"] = error;
>>}
>>
>>and then in my code I have:
>>
>>errorHandler error = (errorHandler)Session["error"];
>>
>>I get:
>>Object Reference not set to an instance of an object
>>(NullReferenceException).
>>
>>I even get the Exception if I do:
>>
>>Session["test"] = "Test";
>>
>>Yes I debug the application
>>.
>>
>.

Session variable scope in a Load Balanced environment

I have the following scenario in a true load balanced environment (without
sticky sessions):
There are 2 ASPX pages. I want to pass an object from the first page to the
second page. On the btnContinue_Click event of Page1.aspx, I create the
object and store it in a session variable. The next statement would be
Response.Redirect("Page2.aspx"). The code appears like this:
private void btnContinue_Click(object sender, EventArgs e)
{
OrderInfo orderInfo = new OrderInfo();
orderInfo.Property1 = "Property1";
orderInfo.Property2 = "Property2" Session["orderInfo"] =
orderInfo;
Response.Redirect("Page2.aspx");
}On Page2.aspx, on the Page_Load event, I retrieve the object from the
Session variable and put it in a OrderInfo object and then remove the
session variable. The code looks similar to below:
void Page_Load(object sender, EventArgs e)
{
OrderInfo orderInfo = new OrderInfo();
orderInfo = (OrderInfo)Session["orderInfo"];
Session.Remove("orderInfo");
}My understanding is - creating the object, putting it in a Session
variable, redirecting to another page and retrieval of the object in the
second page - all these happens in one server call. I don't care if the
Session variable is lost after this call. That is the reason I remove the
variable from session state.
My question is - are there any chances that the Session variable will lose
its value in the above scenario because of load balancing?
Any help will be appriciated.
Thanks!On Wed, 28 Dec 2005 11:57:17 +0530, Vidyadhar Joshi wrote:

> I have the following scenario in a true load balanced environment (without
> sticky sessions):
> There are 2 ASPX pages. I want to pass an object from the first page to th
e
> second page. On the btnContinue_Click event of Page1.aspx, I create the
> object and store it in a session variable. The next statement would be
> Response.Redirect("Page2.aspx"). The code appears like this:
> private void btnContinue_Click(object sender, EventArgs e)
> {
> OrderInfo orderInfo = new OrderInfo();
> orderInfo.Property1 = "Property1";
> orderInfo.Property2 = "Property2" Session["orderInfo"] =
> orderInfo;
> Response.Redirect("Page2.aspx");
> }On Page2.aspx, on the Page_Load event, I retrieve the object from the
> Session variable and put it in a OrderInfo object and then remove the
> session variable. The code looks similar to below:
> void Page_Load(object sender, EventArgs e)
> {
> OrderInfo orderInfo = new OrderInfo();
> orderInfo = (OrderInfo)Session["orderInfo"];
> Session.Remove("orderInfo");
> }My understanding is - creating the object, putting it in a Session
> variable, redirecting to another page and retrieval of the object in the
> second page - all these happens in one server call. I don't care if the
> Session variable is lost after this call. That is the reason I remove the
> variable from session state.
> My question is - are there any chances that the Session variable will lose
> its value in the above scenario because of load balancing?
> Any help will be appriciated.
> Thanks!
In my experience, load balancing (without sticky), will create problems
for you.
You will also have problems with the Session being dumped due to timeout,
restarts of the server, etc.

Session variable scope in a Load Balanced environment

I have the following scenario in a true load balanced environment (without
sticky sessions):

There are 2 ASPX pages. I want to pass an object from the first page to the
second page. On the btnContinue_Click event of Page1.aspx, I create the
object and store it in a session variable. The next statement would be
Response.Redirect("Page2.aspx"). The code appears like this:
private void btnContinue_Click(object sender, EventArgs e)
{
OrderInfo orderInfo = new OrderInfo();
orderInfo.Property1 = "Property1";
orderInfo.Property2 = "Property2" Session["orderInfo"] =
orderInfo;
Response.Redirect("Page2.aspx");
}On Page2.aspx, on the Page_Load event, I retrieve the object from the
Session variable and put it in a OrderInfo object and then remove the
session variable. The code looks similar to below:
void Page_Load(object sender, EventArgs e)
{
OrderInfo orderInfo = new OrderInfo();
orderInfo = (OrderInfo)Session["orderInfo"];
Session.Remove("orderInfo");
}My understanding is - creating the object, putting it in a Session
variable, redirecting to another page and retrieval of the object in the
second page - all these happens in one server call. I don't care if the
Session variable is lost after this call. That is the reason I remove the
variable from session state.

My question is - are there any chances that the Session variable will lose
its value in the above scenario because of load balancing?

Any help will be appriciated.

Thanks!On Wed, 28 Dec 2005 11:57:17 +0530, Vidyadhar Joshi wrote:

> I have the following scenario in a true load balanced environment (without
> sticky sessions):
> There are 2 ASPX pages. I want to pass an object from the first page to the
> second page. On the btnContinue_Click event of Page1.aspx, I create the
> object and store it in a session variable. The next statement would be
> Response.Redirect("Page2.aspx"). The code appears like this:
> private void btnContinue_Click(object sender, EventArgs e)
> {
> OrderInfo orderInfo = new OrderInfo();
> orderInfo.Property1 = "Property1";
> orderInfo.Property2 = "Property2" Session["orderInfo"] =
> orderInfo;
> Response.Redirect("Page2.aspx");
> }On Page2.aspx, on the Page_Load event, I retrieve the object from the
> Session variable and put it in a OrderInfo object and then remove the
> session variable. The code looks similar to below:
> void Page_Load(object sender, EventArgs e)
> {
> OrderInfo orderInfo = new OrderInfo();
> orderInfo = (OrderInfo)Session["orderInfo"];
> Session.Remove("orderInfo");
> }My understanding is - creating the object, putting it in a Session
> variable, redirecting to another page and retrieval of the object in the
> second page - all these happens in one server call. I don't care if the
> Session variable is lost after this call. That is the reason I remove the
> variable from session state.
> My question is - are there any chances that the Session variable will lose
> its value in the above scenario because of load balancing?
> Any help will be appriciated.
> Thanks!
In my experience, load balancing (without sticky), will create problems
for you.
You will also have problems with the Session being dumped due to timeout,
restarts of the server, etc.

Session variable to formview

I would like to do the following :
Dim FV_Str As Object = Session("SesParFormView")
Dim Fv As FormView = FindControl(FV_Str)
I want to assign the content of session variable "SesParFormView" intoa formview variable, and subsequently try to find the formview withfindcontrol.Fv becomes "nothing". What now ?
Thanks in advance.
Maarten


Maarten_Issue wrote:

I would like to do the following :
Dim FV_Str As Object = Session("SesParFormView")
Dim Fv As FormView = FindControl(FV_Str)
I want to assign the content of session variable "SesParFormView" into a formview variable, and subsequently try to find the formview with findcontrol.Fv becomes "nothing". What now ?


FindControl finds the secified control in the Page Controlcollection. In your case you only assigned the session value to a local variable or object. So, it wouldnt be inside the Page control collection. Thats why it is returning null
Im trying to find an existing formview that has been saved in the localsession variable "SesParFormView". FindControl works fine if i put thecontents of the variable manually into it's id field. Also the compiler(VWD Beta 2) complains about not being able to convert "FV_Str" fromFormView to String. It also happens when i try to use the directcast ofctype functions.

Found the solution. See below:
Dim FV_Str As String = Session("SesParFormView")
Dim FV_Str2 As New FormView
If Not (IsNothing(FV_Str)) Then
FV_Str2.ID = FV_Str
Dim Fv As FormView = FV_Str2
If Not (IsNothing(Fv)) Then
Fv.DataSourceID = Nothing
Fv.Visible = False
End If
End If
Now I'm able to find a formview dynamically.
Maarten

Unfortunately the new created FormView "Fv" doesnt "bind" to the realFormView that resides on the form. :S It has no effect when I changethe "DataSourceID" to "Nothing"...What do I have to do to make it bindto the real FormView ? (Other than FindControl and CType)
Some help may be needed :S
Thanks !!
Maarten

Session Variable-InvalidCastException

I use a Session variable to store a custom object (all properties contain
strings) between postbacks. On occasion, mostly when I change and save code,
when I refresh the web page to see the changes, I get an error:
"System.InvalidCastException was unhandled by user code -Unable to cast
object of type 'QueryParameters' to type 'QueryParameters'"
in the function below which is called during Page_Load (_queryParameters =
QueryParameters.getInstance())
Public Shared Function getInstance() As QueryParameters
Dim instance As QueryParameters
If IsNothing(Current.Session(SESSION_VARIABLE)) Then
instance = New QueryParameters()
instance.saveQPToSession()
Else
instance = Current.Session(SESSION_VARIABLE)
End If
Return instance
End Function
When I debug, a valid Session variable exists because the code goes to the
Else statement, and in the Watch window, I can see all the properties of the
custom object in the Session variable. Since 'instance' is typed as
QueryParameters and a Session variable exists that holds the object, I don't
understand why there is an error since these both seem to be typed correctly
as QueryParameters. Even when I explicitly type the session variable
(CType(Current.Session(SESSION_VARIABLE), QueryParameters)) the same error
appears.
If I close the browser completely, everything works, but I hate to have to
close a browser with every iteration of code changes.
Does anyone know why this error appears? Thanks for any help.Hi,
Don Miller wrote:
> I use a Session variable to store a custom object (all properties contain
> strings) between postbacks. On occasion, mostly when I change and save cod
e,
> when I refresh the web page to see the changes, I get an error:
> "System.InvalidCastException was unhandled by user code -Unable to cast
> object of type 'QueryParameters' to type 'QueryParameters'"
The symptoms make me think of that error:
http://weblogs.asp.net/scottgu/arch...ion-issues.aspx
Could that be it?
Greetings,
Laurent

> in the function below which is called during Page_Load (_queryParameters =
> QueryParameters.getInstance())
> Public Shared Function getInstance() As QueryParameters
> Dim instance As QueryParameters
> If IsNothing(Current.Session(SESSION_VARIABLE)) Then
> instance = New QueryParameters()
> instance.saveQPToSession()
> Else
> instance = Current.Session(SESSION_VARIABLE)
> End If
> Return instance
> End Function
> When I debug, a valid Session variable exists because the code goes to the
> Else statement, and in the Watch window, I can see all the properties of t
he
> custom object in the Session variable. Since 'instance' is typed as
> QueryParameters and a Session variable exists that holds the object, I don
't
> understand why there is an error since these both seem to be typed correct
ly
> as QueryParameters. Even when I explicitly type the session variable
> (CType(Current.Session(SESSION_VARIABLE), QueryParameters)) the same error
> appears.
> If I close the browser completely, everything works, but I hate to have to
> close a browser with every iteration of code changes.
> Does anyone know why this error appears? Thanks for any help.
>
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
>> "System.InvalidCastException was unhandled by user code -Unable to cast
> The symptoms make me think of that error:
> http://weblogs.asp.net/scottgu/arch...ion-issues.aspx
> Could that be it?
I tried the simple workaround (changing the web config file system "batch"
to false) and the error message persisted (run the application, type in
garbage in the code-behind, erase the garbage, save the file, hit refresh in
the browser). I am leary of applying the hotfix. I may just end up putting
my properties into hidden fields instead of an object in a Session variable
and forgetting this bug.
Something to do with changing the source code file and compilation.

Session Variable-InvalidCastException

I use a Session variable to store a custom object (all properties contain
strings) between postbacks. On occasion, mostly when I change and save code,
when I refresh the web page to see the changes, I get an error:

"System.InvalidCastException was unhandled by user code -Unable to cast
object of type 'QueryParameters' to type 'QueryParameters'"

in the function below which is called during Page_Load (_queryParameters =
QueryParameters.getInstance())

Public Shared Function getInstance() As QueryParameters
Dim instance As QueryParameters
If IsNothing(Current.Session(SESSION_VARIABLE)) Then
instance = New QueryParameters()
instance.saveQPToSession()
Else
instance = Current.Session(SESSION_VARIABLE)
End If
Return instance
End Function

When I debug, a valid Session variable exists because the code goes to the
Else statement, and in the Watch window, I can see all the properties of the
custom object in the Session variable. Since 'instance' is typed as
QueryParameters and a Session variable exists that holds the object, I don't
understand why there is an error since these both seem to be typed correctly
as QueryParameters. Even when I explicitly type the session variable
(CType(Current.Session(SESSION_VARIABLE), QueryParameters)) the same error
appears.

If I close the browser completely, everything works, but I hate to have to
close a browser with every iteration of code changes.

Does anyone know why this error appears? Thanks for any help.Hi,

Don Miller wrote:

Quote:

Originally Posted by

I use a Session variable to store a custom object (all properties contain
strings) between postbacks. On occasion, mostly when I change and save code,
when I refresh the web page to see the changes, I get an error:
>
"System.InvalidCastException was unhandled by user code -Unable to cast
object of type 'QueryParameters' to type 'QueryParameters'"


The symptoms make me think of that error:
http://weblogs.asp.net/scottgu/arch...ion-issues.aspx
Could that be it?

Greetings,
Laurent

Quote:

Originally Posted by

>
in the function below which is called during Page_Load (_queryParameters =
QueryParameters.getInstance())
>
Public Shared Function getInstance() As QueryParameters
Dim instance As QueryParameters
If IsNothing(Current.Session(SESSION_VARIABLE)) Then
instance = New QueryParameters()
instance.saveQPToSession()
Else
instance = Current.Session(SESSION_VARIABLE)
End If
Return instance
End Function
>
When I debug, a valid Session variable exists because the code goes to the
Else statement, and in the Watch window, I can see all the properties of the
custom object in the Session variable. Since 'instance' is typed as
QueryParameters and a Session variable exists that holds the object, I don't
understand why there is an error since these both seem to be typed correctly
as QueryParameters. Even when I explicitly type the session variable
(CType(Current.Session(SESSION_VARIABLE), QueryParameters)) the same error
appears.
>
If I close the browser completely, everything works, but I hate to have to
close a browser with every iteration of code changes.
>
Does anyone know why this error appears? Thanks for any help.
>
>


--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
>"System.InvalidCastException was unhandled by user code -Unable to cast

Quote:

Originally Posted by

Quote:

Originally Posted by

>object of type 'QueryParameters' to type 'QueryParameters'"


>
The symptoms make me think of that error:
http://weblogs.asp.net/scottgu/arch...ion-issues.aspx
>
Could that be it?


I tried the simple workaround (changing the web config file system "batch"
to false) and the error message persisted (run the application, type in
garbage in the code-behind, erase the garbage, save the file, hit refresh in
the browser). I am leary of applying the hotfix. I may just end up putting
my properties into hidden fields instead of an object in a Session variable
and forgetting this bug.

Something to do with changing the source code file and compilation.

Tuesday, March 13, 2012

Session variables are lost

we have a session variable object that gets lost in the same event call.
I have windows XP Pro as my os with the latest service pack...
I have the .net 1.1 SP1 installed. Even tried installing 1.0 SP2 but that
does not work for me...

Here is what my machine.config looks like:

<sessionState mode="InProc" cookieless="true" timeout="20"/
Any help is appreciated...

Thanks
Guns
www.goondemand.comGuns,

Does the web.config file get changed? Probably because of a virus scanner?
Or do you prob. have another file in your bin directory which is changed
during execution or another configuration file or an access database?

If so you know why your application will restart and (because you save the
session InProc) looses your session.

Greetings

Daniel

"Guns" <gg@.ecokard.com> schrieb im Newsbeitrag
news:ub%23UABeiFHA.1412@.TK2MSFTNGP09.phx.gbl...
> we have a session variable object that gets lost in the same event call.
> I have windows XP Pro as my os with the latest service pack...
> I have the .net 1.1 SP1 installed. Even tried installing 1.0 SP2 but that
> does not work for me...
> Here is what my machine.config looks like:
> <sessionState mode="InProc" cookieless="true" timeout="20"/>
> Any help is appreciated...
> Thanks
> Guns
> www.goondemand.com
>
Try instead of "InProc" this:

<sessionState
mode="StateServer"
stateConnectionString="tcpip=127.0.0.1:42424"
stateNetworkTimeout="10"
sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI"
cookieless="false"
timeout="20"
/
And run the "ASP.NET State Server Service" in Services...

I had the same problem of ramdomly disappearing/reappearing
session-values... Not it works fine.

"Guns" <gg@.ecokard.com> schrieb im Newsbeitrag
news:ub%23UABeiFHA.1412@.TK2MSFTNGP09.phx.gbl...
> we have a session variable object that gets lost in the same event call.
> I have windows XP Pro as my os with the latest service pack...
> I have the .net 1.1 SP1 installed. Even tried installing 1.0 SP2 but that
> does not work for me...
> Here is what my machine.config looks like:
> <sessionState mode="InProc" cookieless="true" timeout="20"/>
> Any help is appreciated...
> Thanks
> Guns
> www.goondemand.com
>