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

Access to the Request object in System.Web.UI.Page derivative...

P: n/a
namespace CIBWeb
{
public class BasePage : System.Web.UI.Page
{
public BasePage()
{
}

protected override void OnInit(EventArgs e)
{
THIS NEXT LINE THROWS EXCEPTION ALSO, CANNOT USE
HttpContext.Current.Request.QueryString["sc"] != string .Empty
if (
HttpContext.Current.Request.Cookies["source_code"].Value.ToString() !=
string.Empty )
{
...
}
...
}
}
}

YIELDS THIS ERROR ...
Server Error in '/CIBWeb' Application.
----------------------------------------------------------------------------
----

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:
Line 64: // no other source code overrides it. ex: user clicks url in
email (email campaign) and then once on the site clicks on a ad banner
(which has
Line 65: // it's own source code), the first source code should still be
the one used
Line 66: if (
HttpContext.Current.Request.Cookies["source_code"].Value.ToString() !=
string.Empty )
Line 67: {
Line 68: SourceCode =
HttpContext.Current.Request.Cookies["source_code"].Value.ToString();
Source File: c:\inetpub\wwwroot\cibweb\src\basepage.cs Line: 66

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
CIBWeb.BasePage.OnInit(EventArgs e) in
c:\inetpub\wwwroot\cibweb\src\basepage.cs:66
CIBWeb.HealthWellness._Default.OnInit(EventArgs e) in
c:\inetpub\wwwroot\CIBWeb\HealthWellness\Default.a spx.cs:74
System.Web.UI.Control.InitRecursive(Control namingContainer)
System.Web.UI.Page.ProcessRequestMain()

ANY IDEAS?
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I believe your problem exists when you have no cookie / querystring present.
You can also perform other checks like HasKeys or Count.
Try retrieving your values with a helper method:

public string getCookie(string strCookie)
{
string cookieValue="";
try
{
cookieValue= Request.Cookies[strCookie].Value;
}
catch(Exception)
{
cookieValue="No Value";
}
return cookieValue;
}

Response.Write(getCookie("source_code"));

-Brian K. Williams

"Terry Mulvany" <te****@mcelroyla.com> wrote in message
news:eW**************@TK2MSFTNGP09.phx.gbl...
namespace CIBWeb
{
public class BasePage : System.Web.UI.Page
{
public BasePage()
{
}

protected override void OnInit(EventArgs e)
{
THIS NEXT LINE THROWS EXCEPTION ALSO, CANNOT USE
HttpContext.Current.Request.QueryString["sc"] != string .Empty
if (
HttpContext.Current.Request.Cookies["source_code"].Value.ToString() !=
string.Empty )
{
...
}
...
}
}
}

YIELDS THIS ERROR ...
Server Error in '/CIBWeb' Application.
-------------------------------------------------------------------------- -- ----

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:
Line 64: // no other source code overrides it. ex: user clicks url in
email (email campaign) and then once on the site clicks on a ad banner
(which has
Line 65: // it's own source code), the first source code should still be the one used
Line 66: if (
HttpContext.Current.Request.Cookies["source_code"].Value.ToString() !=
string.Empty )
Line 67: {
Line 68: SourceCode =
HttpContext.Current.Request.Cookies["source_code"].Value.ToString();
Source File: c:\inetpub\wwwroot\cibweb\src\basepage.cs Line: 66

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
CIBWeb.BasePage.OnInit(EventArgs e) in
c:\inetpub\wwwroot\cibweb\src\basepage.cs:66
CIBWeb.HealthWellness._Default.OnInit(EventArgs e) in
c:\inetpub\wwwroot\CIBWeb\HealthWellness\Default.a spx.cs:74
System.Web.UI.Control.InitRecursive(Control namingContainer)
System.Web.UI.Page.ProcessRequestMain()

ANY IDEAS?

Nov 18 '05 #2

P: n/a
Thanks. I had an epiphany and fixeed this about half an hour ago.
I am just testing for null first.

"Brian K. Williams" <wi*******@millenia.com> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
I believe your problem exists when you have no cookie / querystring present. You can also perform other checks like HasKeys or Count.
Try retrieving your values with a helper method:

public string getCookie(string strCookie)
{
string cookieValue="";
try
{
cookieValue= Request.Cookies[strCookie].Value;
}
catch(Exception)
{
cookieValue="No Value";
}
return cookieValue;
}

Response.Write(getCookie("source_code"));

-Brian K. Williams

"Terry Mulvany" <te****@mcelroyla.com> wrote in message
news:eW**************@TK2MSFTNGP09.phx.gbl...
namespace CIBWeb
{
public class BasePage : System.Web.UI.Page
{
public BasePage()
{
}

protected override void OnInit(EventArgs e)
{
THIS NEXT LINE THROWS EXCEPTION ALSO, CANNOT USE
HttpContext.Current.Request.QueryString["sc"] != string .Empty
if (
HttpContext.Current.Request.Cookies["source_code"].Value.ToString() !=
string.Empty )
{
...
}
...
}
}
}

YIELDS THIS ERROR ...
Server Error in '/CIBWeb' Application.


--------------------------------------------------------------------------
--
----

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
Line 64: // no other source code overrides it. ex: user clicks url in email (email campaign) and then once on the site clicks on a ad banner
(which has
Line 65: // it's own source code), the first source code should still

be
the one used
Line 66: if (
HttpContext.Current.Request.Cookies["source_code"].Value.ToString() !=
string.Empty )
Line 67: {
Line 68: SourceCode =
HttpContext.Current.Request.Cookies["source_code"].Value.ToString();
Source File: c:\inetpub\wwwroot\cibweb\src\basepage.cs Line: 66

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
CIBWeb.BasePage.OnInit(EventArgs e) in
c:\inetpub\wwwroot\cibweb\src\basepage.cs:66
CIBWeb.HealthWellness._Default.OnInit(EventArgs e) in
c:\inetpub\wwwroot\CIBWeb\HealthWellness\Default.a spx.cs:74
System.Web.UI.Control.InitRecursive(Control namingContainer)
System.Web.UI.Page.ProcessRequestMain()

ANY IDEAS?


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.