Problems using HttpContext.Current.Request.Url.Host

  • Thread starter Thread starter Brett R. Wesoloski
  • Start date Start date
B

Brett R. Wesoloski

I am having problems using HttpContext.Current.Request.Url.Host.

I have some code that does this...

if (HttpContext.Current != null)
{

subdomain = HttpContext.Current.Request.Url.Host;

}

Now if I put a break point on the if statement I get this error for the
HttpContext.Current.Request. Request: 'HttpContext.Current.Request' threw
an exception of type 'System.Web.HttpException'

Now if I comment out the subdomain = HttpContext.Current.Request.Url.Host;
and stop at the same break point it works fine.

Now this seems to be a problem with the 3.5 framework because after I
installed it, this code seemed to not work any more.

Any idea's?

TIA,
Brett
 
Brett,

Well, what is the message that is thrown with the exception? That would
help quite a bit.
 
Yes sorry about that.

the message is Request is not available in this context.

Error Code: -2147467259

Stack Trace: a system.web.httpcontext.get_request()


Nicholas Paldino said:
Brett,

Well, what is the message that is thrown with the exception? That
would help quite a bit.


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

Brett R. Wesoloski said:
I am having problems using HttpContext.Current.Request.Url.Host.

I have some code that does this...

if (HttpContext.Current != null)
{

subdomain = HttpContext.Current.Request.Url.Host;

}

Now if I put a break point on the if statement I get this error for the
HttpContext.Current.Request. Request: 'HttpContext.Current.Request'
threw an exception of type 'System.Web.HttpException'

Now if I comment out the subdomain =
HttpContext.Current.Request.Url.Host; and stop at the same break point it
works fine.

Now this seems to be a problem with the 3.5 framework because after I
installed it, this code seemed to not work any more.

Any idea's?

TIA,
Brett
 
the message is Request is not available in this context.

OK; so what *is* the context - i.e. where is this code, and when does
it run? i.e. is it part of a standard ASP.NET pipeline, or something
more exotic?

For the record, *if* this changed when you installed 3.5, then in
reality it is probably a change in "2.0 SP1", not 3.5. I mention this
simply because if it *is* a breaking change, you might need to watch
out for people installing "2.0 SP1" until you have fixed the offending
code.

Marc
 

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