Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Problems using HttpContext.Current.Request.Url.Host

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brett R. Wesoloski - 28 Feb 2008 15:51 GMT
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] - 28 Feb 2008 16:01 GMT
Brett,

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

Signature

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

>I am having problems using HttpContext.Current.Request.Url.Host.
>
[quoted text clipped - 21 lines]
> TIA,
> Brett
Brett R. Wesoloski - 28 Feb 2008 16:52 GMT
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()

> Brett,
>
[quoted text clipped - 27 lines]
>> TIA,
>> Brett
Marc Gravell - 29 Feb 2008 05:28 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.