c# - How to access the current HttpRequestMessage object globally? -


i have method creates httpresponsemessage containing error object returned based on current request media type formatter.

currently, have hardcoded xmlmediatypeformatter i'd able find current request mediatypeformatter @ runtime don't have access current request object since below code exists on separate class library.

private httpresponsemessage create(httpstatuscode statuscode, string errorcode, string errormessage) {     var result = new httpresponsemessage(statuscode)         {             content = new objectcontent<error>(new error()             {                 code = errorcode,                 message = errormessage             }, new xmlmediatypeformatter())         };     return result; } 

how access current httprequestmessage object globally? httpcontext.current.request

if impossible, how implement above method knows formatter should using current request?

it's not impossible have found out. it's added items property of current httpcontext (if there one) =[

httprequestmessage httprequestmessage = httpcontext.current.items["ms_httprequestmessage"] httprequestmessage 

edit:

this of webapi v2 .. cannot sure of previous versions.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -