Binesh Nambiar C
Binesh Nambiar C

Reputation: 162

How to add a request wise variable in httpcontext

In HttpContext(Or some thing like this) I need to add a temperory variable from a controller which need to available through out the request processing(Request wise variable). But the HttpContext.Current.Request is readonly. If i'm adding in Items its not getting outside. How can i achieve this

Thanks & Regards Binesh Nambiar C

Upvotes: 3

Views: 6701

Answers (1)

NightOwl888
NightOwl888

Reputation: 56869

You are looking for HttpContext.Items, which is a dictionary that can be used to store items for the duration of the current request. It goes out of scope at the end of the request.

// Set
HttpContext.Items["Customer"] = customer;

// Get
var customer = HttpContext.Items["Customer"];

Upvotes: 7

Related Questions