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

Problems using HttpContext.Current.Request.Url.Host

P: n/a
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

Feb 28 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Brett,

Well, what is the message that is thrown with the exception? That would
help quite a bit.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brett R. Wesoloski" <br*********@planadmininc.comwrote in message
news:39**********************************@microsof t.com...
>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

Feb 28 '08 #2

P: n/a
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]" <mv*@spam.guard.caspershouse.comwrote in
message news:O1**************@TK2MSFTNGP03.phx.gbl...
Brett,

Well, what is the message that is thrown with the exception? That
would help quite a bit.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brett R. Wesoloski" <br*********@planadmininc.comwrote in message
news:39**********************************@microsof t.com...
>>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

Feb 28 '08 #3

P: n/a
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
Feb 29 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.