Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   check login with user control (http://www.velocityreviews.com/forums/t771651-check-login-with-user-control.html)

Tim T 11-06-2003 02:14 AM

check login with user control
 
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




All times are GMT. The time now is 09:09 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.