HttpResponse not working

  • Thread starter Thread starter Kavvy
  • Start date Start date
K

Kavvy

Hi,

Can anyone tell me why the following code produces the error

"An object reference is required for the nonstatic field, method, or
property 'System.Web.HttpResponse.Redirect(string)'"
 
Kavvy said:
Hi,

Can anyone tell me why the following code produces the error

"An object reference is required for the nonstatic field, method, or
property 'System.Web.HttpResponse.Redirect(string)'"

Oops,

here is the code

private void errorScreen(string errorString)
{
HttpContext.Current.Session["error"] = errorString;
HttpResponse.Redirect("Errors.aspx"); // << produces error
}
 
Kavvy,

The reason for this is that the Redirect method is an instance method,
not a static method. You have to get an instance of the HttpResponse
method, like this:

private void errorScreen(string errorString)
{
HttpContext.Current.Session["error"] = errorString;
HttpContext.Current.Reponse.Redirect("Errors.aspx"); // << produces
error
}

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Kavvy said:
Kavvy said:
Hi,

Can anyone tell me why the following code produces the error

"An object reference is required for the nonstatic field, method, or
property 'System.Web.HttpResponse.Redirect(string)'"

Oops,

here is the code

private void errorScreen(string errorString)
{
HttpContext.Current.Session["error"] = errorString;
HttpResponse.Redirect("Errors.aspx"); // << produces error
}
 

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

Back
Top