Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Casting HttpRequestMessage.Properties["MS_RequestContext"] to OwinHttpRequestContext

Casting HttpRequestMessage.Properties["MS_RequestContext"] to OwinHttpRequestContext

Scheduled Pinned Locked Moved C#
helpcsharpvisual-studiodebuggingquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alaric_
    wrote on last edited by
    #1

    So this is weird. I'm trying to manually fiddle with a property of my MS_RequestContext during Controller Activation inside my WebApi's CompositionRoot. my Create method receives a System.Net.Http.HttpRequestMessage argument. I can drill down request to grab

    request.Properties["MS_RequestContext"]

    Properties is a

    dictionary

    That object will be an OwinHttpRequestContext at runtime. But whenever I attempt to cast, so that I can access the properties on the RequestContext, I get a naughty-gram from Visual Studio

    (request.Properties["MS_RequestContext"] as OwinHttpRequestContext).Request.Properties;

    The error that comes back is:

    The type or namespace 'OwinHttpRequestContext' could not be found (are you missing a using directive or an assembly reference?)

    Well...OwinHttpRequestContext lives inside the System.Web.Http.Owin namespace. My references are all set up. I even have added a using statement for good measure. So the crazy part is that if I remove my code that attempts to directly reference request.Properties, but instead set a breakpoint inside my Create method, I can -through a watch- execute

    (request.Properties["MS_RequestContext"] as System.Web.Http.Owin.OwinHttpRequestContext).Request.Properties

    without issue. I can confirm that I have no problem modifying the properties at runtime through the immediate window. Why am I not able to perform this same cast at build time? I've inspected the

    HttpContext.Current.GetOwinContext()

    for access to the property that I need to manipulate, but it's not available on IOwinContext.

    "I need build Skynet. Plz send code"

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups