53

What is the purpose of HttpRequestMessage.Properties?

I'm wondering if it provides something useful for my application.

2 Answers 2

6

In Web Api it contains some special flags: https://www.strathweb.com/2013/08/asp-net-web-api-2-and-httprequestcontext/

For example, IncludeErrorDetail, IsLocal, ClientCertificate are stored in the dictionary, but have properties for easy access.

Sign up to request clarification or add additional context in comments.

2 Comments

Apart from the high level description, how are they placed in the HTTP request? As headers? In the body?
I would also be interested to understand where and how these properties are stored in the request. In particular because the dictionary values are of type Object, so are they serialized? To Json, to something else?
3

I found this statement from THOMAS LEVESQUE'S .NET BLOG which is how I was hoping to use it. MS or other places don't really describe it correctly... that we can use it however we want to carry per request information. In my case, store information about the destination so that I can validate the certificate per destination.

Let's see how we can associate a timeout value to a request. The HttpRequestMessage class has a Properties property, which is a dictionary in which we can put whatever we need. We're going to use this to store the timeout for a request, and to make things easier, we'll create extension methods to access the value in a strongly-typed fashion:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.