Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Storing Contextual Data During A Request

I am writing an ASP.NET application that initializes some contextual data based on stuff sent through the Request object. How should I be storing this so that it is only visible to objects dealing with the request?

Essentially I have an HttpModule that looks at the request, and does something based on the incoming data:

public void OnBeginRequest(object sender, EventArgs e){
    if((sender as HttpApplication).Request.Url.Host == "something"){
        // Store some extra information here
    }
}

And then I want to retrieve the data later on in the pipeline, in a view

<%: somehowGetRequestSpecificData.MyProperty %>

How and where should I be storing that stuff?

like image 333
Krisc Avatar asked Dec 16 '22 21:12

Krisc


1 Answers

IMO - HTTPContext.Items is the best way to do this.

Ref.: https://web.archive.org/web/20201202215202/https://www.4guysfromrolla.com/articles/060904-1.aspx

HTH.

like image 157
Sunny Avatar answered Dec 29 '22 11:12

Sunny