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
Post a Comment