Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Missing Viewstate

Reply
Thread Tools

Missing Viewstate

 
 
Kev
Guest
Posts: n/a
 
      11-04-2009
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
 
Reply With Quote
 
 
 
 
Kev
Guest
Posts: n/a
 
      11-04-2009
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.


On 4 Nov, 16:49, Kev <(E-Mail Removed)> wrote:
> 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


 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      11-04-2009

"Kev" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
David
Guest
Posts: n/a
 
      11-04-2009
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


"Kev" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Kev
Guest
Posts: n/a
 
      11-04-2009
On 4 Nov, 17:23, "Scott M." <(E-Mail Removed)> wrote:
> "Kev" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
>
>
> > 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- 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
 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      11-04-2009

"Kev" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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.


On 4 Nov, 16:49, Kev <(E-Mail Removed)> wrote:
> 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


 
Reply With Quote
 
Kev
Guest
Posts: n/a
 
      11-04-2009
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
 
Reply With Quote
 
Kev
Guest
Posts: n/a
 
      11-04-2009
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.
 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      11-04-2009
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


 
Reply With Quote
 
Kev
Guest
Posts: n/a
 
      11-04-2009
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with ViewState: "function 'ViewState.get_Item' evaluated and returned null" Steph ASP .Net 2 05-11-2011 02:35 PM
Errors: Failed to load viewstate. & Validation of viewstate MAC failed. sck10 ASP .Net 6 09-01-2006 05:59 PM
Loading usercontrols, viewstate problem, slighly different from all others "viewstate uc problems" please help... ujjc001 ASP .Net 0 07-27-2005 01:52 PM
Viewstate errors... how do I get viewstate working? mark ASP .Net Building Controls 0 02-20-2004 02:17 PM
Corrupted ViewState (Yes, another issue concerning viewstate) Ben Rush ASP .Net 2 12-05-2003 04:17 PM



Advertisments