| Author |
|
njaskot New User

Joined: August/24/2006
Online Status: Offline Info: 6
|
| Added: August/24/2006 at 11:01pm | IP Logged
|
|
|
Hi i am trying to caputure the session variable for the logged in user.
After i login i am directed to the page where i am trying to grab the login name.
It seems that the initial load of the page, the value is not there. However, when i manually refresh the page (f5) the value is there!?
Any idea, what i am doing wrong?
Here are some snippets (C# 2.0)....
aspx.cs page (code behind) protected void Page_Load(object sender, EventArgs e) { if (Session["Username"] != null) { Response.Write("Username = " + Session["Username"].ToString() + "<br>"); } else { Response.Write("sorry.......<br>"); }
}
aspx page
<%@ Register TagPrefix="aspprotectauthentication" TagName="checkaccess" Src="../protectpage.ascx" %>
and
<html>
<head id="Head1" runat="server"> <aspprotectauthentication:checkaccess CHECKFOR="" GROUPACCESS="" runat="server"></aspprotectauthentication:checkaccess& gt;
First time, it echos 'sorry', after a refresh the page echos 'username = xxxx' ?
Thanks,
Nathan
|
| Back to Top |
|
| |
cwilliams Admin Group

CJWSoft Web Software Developer
Joined: April/06/2004
Online Status: Offline Info: 1769
|
| Added: August/24/2006 at 11:14pm | IP Logged
|
|
|
not really sure... I know my example protected page gets the info ok..... what happens if you try to grab the session info using the httpcontext.current like so
HttpContext.Current.Session("Username")
__________________
Best Regards,
Christopher Williams
www.CJWSoft.com
|
| Back to Top |
|
| |
njaskot New User

Joined: August/24/2006
Online Status: Offline Info: 6
|
| Added: August/24/2006 at 11:34pm | IP Logged
|
|
|
same thing...
i also tried something like
if(!Page.IsPostBack) { check for session here }
i see that your testprotect.aspx page works...as expected. 
i will try looking more closely. It seems pretty simple. Do you happen to have a working c# example?
It is just really odd... 
I would like to send you the url, and test login, so you can see, if possible
|
| Back to Top |
|
| |
njaskot New User

Joined: August/24/2006
Online Status: Offline Info: 6
|
| Added: August/24/2006 at 11:53pm | IP Logged
|
|
|
i figured it out...kinda
if i put <% Response.Write("Username = " + Session["Username"].ToString() + "<br>"); %>
in the aspx page it works...the first time it hits the page.
However, like i said, if i put it in the code behind, it doesn't (until the refresh).
So i litery have one saying 'sorry' (it's not there) and the other showing the value?! 
I think i can just work with this...but still is just strange.
any ideas?
|
| Back to Top |
|
| |
cwilliams Admin Group

CJWSoft Web Software Developer
Joined: April/06/2004
Online Status: Offline Info: 1769
|
| Added: August/25/2006 at 12:37am | IP Logged
|
|
|
sorry, no working c# example..
Maybe the pageload is your problem.. maybe pageload technically happens before my control envokes thus the values wouldnt exist
Try just putting a function in your code behind and grabbing it when you need it instead of the page load deal..
__________________
Best Regards,
Christopher Williams
www.CJWSoft.com
|
| Back to Top |
|
| |
njaskot New User

Joined: August/24/2006
Online Status: Offline Info: 6
|
| Added: August/25/2006 at 12:56pm | IP Logged
|
|
|
i think you are correct.
However, i did a bit of playing around and grabbing it in the front end page will work fine for me.
All looks good, thanks for your help! 
|
| Back to Top |
|
| |