check login with user control

T

Tim T

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="+thisParent);

}

}

}

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
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top