Missing Viewstate

K

Kev

Hi all,

I hope someone understands this better than I do. I have an ASP.NET
app using a MasterPage (which I actually created in DreamWeaver then
copied the HTML to the MasterPage). So far so good.

The master page has a fancy nav menu (a SpryMenu) at the top - this
does not cause post backs - just a fancy collection of hyperlinks.

I want to track the currently logged in user in the View State. I do
this thus:

If (correct password)
{
Session["USERID"] = userid;
Server.Transfer("MyAccount.aspx");
}

And in all pages do something like

if (Session["USERID"] == null)
Response.Redirect("Login.aspx");

At this point I am on MyAccount.aspx via a Server.Transfer. I can
choose any page in my fancy nav menu, which are just hyperlinks, and
in the respective Page_Load I can get the userid from the session.
But only the once. That page will load fine and display user
information from the database etc. But if I choose another page from
the nav menu - even the same page, the Session variables have gone.
The Session.SessionID is the same but Session.Count is 0.

Can anyone shed any light on what may be happening behind the scenes -
I am perplexed.

Thanks

Kev
 
K

Kev

Hi again,

further investigation leads me to believe that something in the eBay
API is causing the vewstate to get reset. Which is odd as the eBay
API should not user the viewstate - what if it was a desktop client
application? However, it does make a web service call.

If I remove the eBay API SOAP call the problem I previously described
vanishes and the viewstate remains intact across pages in the nav bar
despite none of them doing postbacks. Is this correct or just luck?

Should making a web service call confuse the view state?

I believe this is still the correct place for this discussion but if
not will accept any guidance to the correct place.

Thanks all.
 
S

Scott M.

Kev said:
Hi all,

I hope someone understands this better than I do. I have an ASP.NET
app using a MasterPage (which I actually created in DreamWeaver then
copied the HTML to the MasterPage). So far so good.

The master page has a fancy nav menu (a SpryMenu) at the top - this
does not cause post backs - just a fancy collection of hyperlinks.

I want to track the currently logged in user in the View State. I do
this thus:

If (correct password)
{
Session["USERID"] = userid;
Server.Transfer("MyAccount.aspx");
}

And in all pages do something like

if (Session["USERID"] == null)
Response.Redirect("Login.aspx");

At this point I am on MyAccount.aspx via a Server.Transfer. I can
choose any page in my fancy nav menu, which are just hyperlinks, and
in the respective Page_Load I can get the userid from the session.
But only the once. That page will load fine and display user
information from the database etc. But if I choose another page from
the nav menu - even the same page, the Session variables have gone.
The Session.SessionID is the same but Session.Count is 0.

Can anyone shed any light on what may be happening behind the scenes -
I am perplexed.

Thanks

Kev

First, I'd ensure that sessions are enabled and configured correctly in IIS.

Second, you need to check your browser's cookie setting to ensure that
session cookies are allowed.

Third, what does your scenario have to do with ViewState as you are not
using it in the description you gave us?

-Scott
 
D

David

This is not viewstate, but session.

From what I remember from classic asp, the page has to be delivered to the
browser in order that the session is set up correctly. Sessions use cookies
to track them.

Here, you are setting the session, then redirecting immediately (on the
server, so the page is not even being sent to the client), hence the session
cookie is not being dropped to the client.

Instead, why not use the login tools from .NET and use the
RedirectFromLoginPage(username, false) (but you need the ReturnUrl in your
querystring) or the SetAuthCookie(username, false)...

This will set up your authentication and in each page you can then check if
the user is authenticated, User.Identity.IsAuthenticated


--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
K

Kev

I hope someone understands this better than I do.  I have an ASP.NET
app using a MasterPage (which I actually created in DreamWeaver then
copied the HTML to the MasterPage).  So far so good.
The master page has a fancy nav menu (a SpryMenu) at the top - this
does not cause post backs - just a fancy collection of hyperlinks.
I want to track the currently logged in user in the View State.  I do
this thus:
If (correct password)
{
   Session["USERID"] = userid;
   Server.Transfer("MyAccount.aspx");
}
And in all pages do something like
if (Session["USERID"] == null)
                   Response.Redirect("Login.aspx");
At this point I am on MyAccount.aspx via a Server.Transfer.  I can
choose any page in my fancy nav menu, which are just hyperlinks, and
in the respective Page_Load I can get the userid from the session.
But only the once.  That page will load fine and display user
information from the database etc.  But if I choose another page from
the nav menu - even the same page, the Session variables have gone.
The Session.SessionID is the same but Session.Count is 0.
Can anyone shed any light on what may be happening behind the scenes -
I am perplexed.

Kev

First, I'd ensure that sessions are enabled and configured correctly in IIS.

Second, you need to check your browser's cookie setting to ensure that
session cookies are allowed.

Third, what does your scenario have to do with ViewState as you are not
using it in the description you gave us?

-Scott- Hide quoted text -

- Show quoted text -

Thanks Scott - you just beat me to it.

Forget all mention of ViewState. I am not using the ViewState at
all. I am primarily interested in the Session state.

I have checked IIS. It is configured to use in process session and
uses cookies with a 20 minute time out.

The browser is correctly observing cookies.

When I run through the debugger, the session id remains constant at my
break points so I am sure this is fine.

I execute the web service and all the session elements are there. But
when I hit the same break point (first line in Page_Load) they have
gone and Session.Count is a red zero. Becuase of the web service
call, it is getting reset.

The question is, what is the web service call doing to cause the
session to get reset? I have the web service source and it doesn't
appear to be doing anything - is it an IIS thing?

Thanks again

Kevin
 
S

Scott M.

Hi again,

further investigation leads me to believe that something in the eBay
API is causing the vewstate to get reset. Which is odd as the eBay
API should not user the viewstate - what if it was a desktop client
application? However, it does make a web service call.

If I remove the eBay API SOAP call the problem I previously described
vanishes and the viewstate remains intact across pages in the nav bar
despite none of them doing postbacks. Is this correct or just luck?

Should making a web service call confuse the view state?

I believe this is still the correct place for this discussion but if
not will accept any guidance to the correct place.

Thanks all.


Hi all,

I hope someone understands this better than I do. I have an ASP.NET
app using a MasterPage (which I actually created in DreamWeaver then
copied the HTML to the MasterPage). So far so good.

The master page has a fancy nav menu (a SpryMenu) at the top - this
does not cause post backs - just a fancy collection of hyperlinks.

I want to track the currently logged in user in the View State. I do
this thus:

If (correct password)
{
Session["USERID"] = userid;
Server.Transfer("MyAccount.aspx");

}

And in all pages do something like

if (Session["USERID"] == null)
Response.Redirect("Login.aspx");

At this point I am on MyAccount.aspx via a Server.Transfer. I can
choose any page in my fancy nav menu, which are just hyperlinks, and
in the respective Page_Load I can get the userid from the session.
But only the once. That page will load fine and display user
information from the database etc. But if I choose another page from
the nav menu - even the same page, the Session variables have gone.
The Session.SessionID is the same but Session.Count is 0.

Can anyone shed any light on what may be happening behind the scenes -
I am perplexed.

Thanks

Kev

You didn't mention anything about eBay in your original post, which
certainly can contribute to the issue. You'll need to be clearer as to what
eBay's systems have to do with your web application and how eBay affects
your login. eBay has a published set of API's for developers wanting to
automate thier functions.

But, as I said in my last message, you haven't told or shown us anything
about your site that relates to ViewState, you've discussed the problem you
are having with Session state, which is entirely different than ViewState.

-Scott
 
K

Kev

Hi Scott,

you are corrrect. My apologies. I didn't believe eBay APIs were at
fault when first posting. But I admit being new to ASP.NET I was
confusing the ViewState session state issue.

My issue is that a call the eBay API is resetting the Session state.

Why I do not know as the eBay API should not know I am using a
SessionState as I could be writing a WinForms app. So I am wondering
if a .NET call the API makes is upsetting the .NET framework some how.

Am still investigating but any thoughts appreciated.

Cheers
 
K

Kev

Ok - I now know which the offending line of code is. It is in the
eBay API and its

LogMessage(url, MessageType.Information,
MessageSeverity.Informational);

Looks pretty innocent, and what it does by stepping through it appears
innocent too. Doesn't even look at the Session state. But something
it is doing is sending ASP.NET into a spin. Not sure if this is
correct place for this discussion but if anyone has any similar
experiences please do feedback one way or another.

Thanks again - particularly to Scott.
 
S

Scott M.

It would be best if you could post your complete code, so we can see exactly
what you are doing.

But, I do believe that David is correct, that using Server.Transfer is not
transfering your session state. It's working the first time because of the
initial session variable you set, but after that it's being lost. Do you
have a specific reason for using Transfer vs. Redirect, which would solve
the problem.

- Scott
 
K

Kev

Apologies - I never even saw Davids reply.

David, your comments make sense and I will look into using a different
method of UserAuthentication.

However, the current situation is that a call to the eBay APIs is
causing the session to get reset? What would cause this?

I sm still trying to identify the exact line of code causing this.

Kevin.
 
K

Kev

Getting nearer - but its more complicated. The Logging issue above is
still worrying but I have commented that out. This code appears to be
the offender

HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri);
request.ProtocolVersion = HttpVersion.Version10;
request.Headers.Add("Accept-Encoding", "gzip, deflate");
if (mCallMetrics != null)
{
mCallMetrics.NetworkSendStarted = DateTime.Now;
request.Headers.Add("X-EBAY-API-METRICS", "true");
}
return request;

However, the code then goes on to do some trickery reading and writing
to memorystreams. Could this be upsetting the session being delivered
to the browser?
 
K

Kev

But, I do believe that David is correct, that using Server.Transfer is not
transfering your session state. It's working the first time because of the
initial session variable you set, but after that it's being lost. Do you
have a specific reason for using Transfer vs. Redirect, which would solve
the problem.
- Scott
Maybe, but when offending code is commented out as discussed I can
visit the page as often as I want and the session remains in tact.
Something somewhere is upsetting the session.
 
K

Kev

OK - some code - but its getting detailed so hope someone can help.

After invoking the webservice the code ends up here

public override void ProcessMessage
(System.Web.Services.Protocols.SoapMessage Message) {
if ((Message.Stage ==
System.Web.Services.Protocols.SoapMessageStage.BeforeSerialize)) {
}
else {
if ((Message.Stage ==
System.Web.Services.Protocols.SoapMessageStage.AfterSerialize)) {
this.SaveRequestMessage(Message);
this.Copy(mStrNew, mStrOld);
}
else {
if ((Message.Stage ==
System.Web.Services.Protocols.SoapMessageStage.BeforeDeserialize)) {
this.SaveResponseMessage(Message);
}
else {
if ((Message.Stage ==
System.Web.Services.Protocols.SoapMessageStage.AfterDeserialize)) {
}
else {
throw new System.ArgumentException
(System.String.Format
(System.Globalization.CultureInfo.InvariantCulture, "Invalid Soap
Message stage [{0}]", Message.Stage), "Message");
}
}
}
}
}


It actually traces to this part
if ((Message.Stage ==
System.Web.Services.Protocols.SoapMessageStage.AfterSerialize)) {
this.SaveRequestMessage(Message);
this.Copy(mStrNew, mStrOld);

And it si the copy routine which causes the problem (but also gets me
the data I need).

/// <summary>
///
/// </summary>
/// <param name="StrFrom"></param>
/// <param name="StrTo"></param>
private void Copy(System.IO.Stream StrFrom, System.IO.Stream
StrTo) {
if (StrFrom.CanSeek) {
StrFrom.Position = 0;
}
System.IO.TextReader TxtReader = new System.IO.StreamReader
(StrFrom);
System.IO.TextWriter TxtWriter = new System.IO.StreamWriter
(StrTo);
TxtWriter.WriteLine(TxtReader.ReadToEnd());
TxtWriter.Flush();
if (StrTo.CanSeek) {
StrTo.Position = 0;
}
}

Is something there stopping the session propagating?
 
K

Kev

PROBLEM SOLVED!!!!!

http://weblogs.asp.net/owscott/archive/2006/02/21/438678.aspx

The eBay API was writing a log file in the bin folder!!!!! And a
change here causes a session reset. I have moed the log file and
problem solved. Should of stuck to my first LogMessage hunch!

Thank you both for your help! GOing to scour some groups for 10
minutes now answering other peeoples questions (on sql) where I can!

Kevin
 
S

Scott M.

Kev said:
PROBLEM SOLVED!!!!!

http://weblogs.asp.net/owscott/archive/2006/02/21/438678.aspx

The eBay API was writing a log file in the bin folder!!!!! And a
change here causes a session reset. I have moed the log file and
problem solved. Should of stuck to my first LogMessage hunch!

Thank you both for your help! GOing to scour some groups for 10
minutes now answering other peeoples questions (on sql) where I can!

Kevin

Good investigative work. Good luck.

-Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top