By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,079 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,079 IT Pros & Developers. It's quick & easy.

check login with user control

P: n/a
Hi,
I have a web application that has a number of users who administer their own
data... i have several pages that check to see if a valid userID session
exists, and if not, send them to a Login.aspx page (where a userID session
is generated upon successful login). my pages are user specific, so each
page will load data specific to that user (hence the need to maintain a
userID).

if users attempt to hit a page that requires a userID, and the
Session["supplierID"] returns null then they will be sent to a Login page.
I have made a user control CheckLogin.axcs that checks for this session var
and redirects to the login page if it doesn't exist
here is the code for the Page_Load event in the user control:

private void Page_Load(object sender, System.EventArgs e)

{

string thisParent = this.Parent.Page.ToString();

thisParent = thisParent.Substring(4,thisParent.Length - 9);

if(Session["supplierID"] == null)

{

HttpCookie cookie = Request.Cookies["supplierID"];

if (cookie != null)

{

Session["supplierID"] = cookie.Value.ToString();

}

else

{

Server.Transfer("Login.aspx?callingPage="+thisPare nt);

}

}

}

this only works fine on parent pages that don't actually look for the
Session["supplierID"]

when i host this in a page on a page that looks for Session["supplierID"]
in the Page_Load then i get this error:

Object reference not set to an instance of an object.
on this line:
spGetSE.Parameters["@supplierID"].Value = Session["supplierID"].ToString();

obviously this is because the session object doesn't exist, but i shouldn't
have even go here, i would have thought that the user control would have
sent me to the Login.aspx page before getting here.

How do people do this properly? it must be common to want to check and
redirect on pages using user controls?

if someone could advise me how to get the user controls Page_Load event to
fire before the parent pages checks for the invalid session it would be
great

Thanks for your help

Tim
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.