Connecting Tech Pros Worldwide Forums | Help | Site Map

Problems using HttpContext.Current.Request.Url.Host

Brett R. Wesoloski
Guest
 
Posts: n/a
#1: Feb 28 '08
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


Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
#2: Feb 28 '08

re: Problems using HttpContext.Current.Request.Url.Host


Brett,

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


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"Brett R. Wesoloski" <brwesoloski@planadmininc.comwrote in message
news:39193C72-66D3-446F-A87C-BF6B43023E91@microsoft.com...
Quote:
>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 R. Wesoloski
Guest
 
Posts: n/a
#3: Feb 28 '08

re: Problems using HttpContext.Current.Request.Url.Host


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 [.NET/C# MVP]" <mvp@spam.guard.caspershouse.comwrote in
message news:O1BhaLieIHA.4880@TK2MSFTNGP03.phx.gbl...
Quote:
Brett,
>
Well, what is the message that is thrown with the exception? That
would help quite a bit.
>
>
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
>
"Brett R. Wesoloski" <brwesoloski@planadmininc.comwrote in message
news:39193C72-66D3-446F-A87C-BF6B43023E91@microsoft.com...
Quote:
>>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
>>
>
>
Marc Gravell
Guest
 
Posts: n/a
#4: Feb 29 '08

re: Problems using HttpContext.Current.Request.Url.Host


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
Closed Thread