T
Tim T
Hi, I'm new to .NET and am still trying to get my head around OO concepts.
I am building an asp.net app and on several pages i want to check to see if
a session object exists, if so - contine to show the page, if not check if
cookie exists, if no cookie then redirect to a login page.
This is easy enough, but now i want to put this functionallity in a class so
that i can just call a checkSupplierID method from that class easily from
any page
This is what i have done:
//method in tools class
public void checkSupplierIDSession()
{
if(Session["supplierID"] == null)
{
HttpCookie cookie = Request.Cookies["supplierID"];
if (cookie != null)
{
Session["supplierID"] = cookie.Value.ToString();
}
else
{
Server.Transfer("Login.aspx?callingPage=" +
this.Page.ToString().Substring(4,this.Page.ToString().Length - 9));
//redirect with this page as calling page
}
}
}
code in aspx.cs code behind file on page i want to check:
private void Page_Load(object sender, System.EventArgs e)
{
tools.checkSupplierIDSession();
}
I get this error when trying to compile:
An object reference is required for the nonstatic field, method, or property
'tools.checkSupplierIDSession()'
Initially the method was static, but that meant that i couldn't use the
Session, Request, and this.Page properties on the calling page?
can someone please advise on the best way to do what i am trying to achieve?
Thanks for your help
Tim
I am building an asp.net app and on several pages i want to check to see if
a session object exists, if so - contine to show the page, if not check if
cookie exists, if no cookie then redirect to a login page.
This is easy enough, but now i want to put this functionallity in a class so
that i can just call a checkSupplierID method from that class easily from
any page
This is what i have done:
//method in tools class
public void checkSupplierIDSession()
{
if(Session["supplierID"] == null)
{
HttpCookie cookie = Request.Cookies["supplierID"];
if (cookie != null)
{
Session["supplierID"] = cookie.Value.ToString();
}
else
{
Server.Transfer("Login.aspx?callingPage=" +
this.Page.ToString().Substring(4,this.Page.ToString().Length - 9));
//redirect with this page as calling page
}
}
}
code in aspx.cs code behind file on page i want to check:
private void Page_Load(object sender, System.EventArgs e)
{
tools.checkSupplierIDSession();
}
I get this error when trying to compile:
An object reference is required for the nonstatic field, method, or property
'tools.checkSupplierIDSession()'
Initially the method was static, but that meant that i couldn't use the
Session, Request, and this.Page properties on the calling page?
can someone please advise on the best way to do what i am trying to achieve?
Thanks for your help
Tim