Problems using HttpContext.Current.Request.Url.Host

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brett R. Wesoloski

    Problems using HttpContext.Current.Request.Url.Host

    I am having problems using HttpContext.Cur rent.Request.Ur l.Host.

    I have some code that does this...

    if (HttpContext.Cu rrent != null)
    {

    subdomain = HttpContext.Cur rent.Request.Ur l.Host;

    }

    Now if I put a break point on the if statement I get this error for the
    HttpContext.Cur rent.Request. Request: 'HttpContext.Cu rrent.Request' threw
    an exception of type 'System.Web.Htt pException'

    Now if I comment out the subdomain = HttpContext.Cur rent.Request.Ur l.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]

    #2
    Re: Problems using HttpContext.Cur rent.Request.Ur l.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.co m

    "Brett R. Wesoloski" <brwesoloski@pl anadmininc.comw rote in message
    news:39193C72-66D3-446F-A87C-BF6B43023E91@mi crosoft.com...
    >I am having problems using HttpContext.Cur rent.Request.Ur l.Host.
    >
    I have some code that does this...
    >
    if (HttpContext.Cu rrent != null)
    {
    >
    subdomain = HttpContext.Cur rent.Request.Ur l.Host;
    >
    }
    >
    Now if I put a break point on the if statement I get this error for the
    HttpContext.Cur rent.Request. Request: 'HttpContext.Cu rrent.Request' threw
    an exception of type 'System.Web.Htt pException'
    >
    Now if I comment out the subdomain = HttpContext.Cur rent.Request.Ur l.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
    >

    Comment

    • Brett R. Wesoloski

      #3
      Re: Problems using HttpContext.Cur rent.Request.Ur l.Host

      Yes sorry about that.

      the message is Request is not available in this context.

      Error Code: -2147467259

      Stack Trace: a system.web.http context.get_req uest()


      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
      message news:O1BhaLieIH A.4880@TK2MSFTN GP03.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]
      - mvp@spam.guard. caspershouse.co m
      >
      "Brett R. Wesoloski" <brwesoloski@pl anadmininc.comw rote in message
      news:39193C72-66D3-446F-A87C-BF6B43023E91@mi crosoft.com...
      >>I am having problems using HttpContext.Cur rent.Request.Ur l.Host.
      >>
      >I have some code that does this...
      >>
      >if (HttpContext.Cu rrent != null)
      > {
      >>
      > subdomain = HttpContext.Cur rent.Request.Ur l.Host;
      >>
      > }
      >>
      >Now if I put a break point on the if statement I get this error for the
      >HttpContext.Cu rrent.Request. Request: 'HttpContext.Cu rrent.Request'
      >threw an exception of type 'System.Web.Htt pException'
      >>
      >Now if I comment out the subdomain =
      >HttpContext.Cu rrent.Request.U rl.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
      >>
      >
      >

      Comment

      • Marc Gravell

        #4
        Re: Problems using HttpContext.Cur rent.Request.Ur l.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

        Comment

        Working...