Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 978
Binesh Nambiar C Avatar asked Apr 08 '26 14:04

Binesh Nambiar C


1 Answers

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"];
like image 150
NightOwl888 Avatar answered Apr 10 '26 02:04

NightOwl888



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!