locked
What is the point of definnig Asp.net Intrinsic Objects In different places and what is the different betwen them? RRS feed

  • Question

  • User234527241 posted

    I found out there are different classes that Asp.net Intrinsic Objects(AIOs) are defined in them.

    I want to know why?  what is the logic and the reason behind this ?

    You can find AIOs in these three different classes:
    I am not aware of any other classes in Asp.net

    1. HttpContext
    2. HttpApplication
    3. Page Class

    For example I am wondering that   HttpContext_instance.Request   and   HttpApplication_instance.Request   and  Page_instance.Request  are the same or Not?
    And also what about the Application object in these three different places? And what about other AIOs?

    Monday, June 8, 2015 4:39 AM

Answers

  • User753101303 posted

    Hi,

    Likely just as a convenience. This is quite at the core of a web application so they made it available directly from several classes. You can also look at http://referencesource.microsoft.com/

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 8, 2015 5:03 AM
  • User-821857111 posted

    my question has another part too , what is the difference  between them?
    There is no difference between Page.Request. HttpContext.Request or HttpApplication.Request. The type is always HttpRequest and they all provide access to the same thing: the current Request object. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 8, 2015 9:24 AM
  • User-821857111 posted

    if I understand it correctly , it implies that there are some differences

    It depends on what you mean by "difference". To all practical intents, the value is the same thing. They are of course different in that they are properties of different objects. But that is self-evident.

    how its possible for us to using AIOs without object instantiation ?
    Static properties are not associated with an instance of an object. https://msdn.microsoft.com/en-us/library/79b3xss3.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 8, 2015 3:05 PM
  • User753101303 posted

    For example look at http://referencesource.microsoft.com/#System.Web/UI/Page.cs

    You'll see for example :

     private void SetIntrinsics(HttpContext context, bool allowAsync) {
            _context = context;
            _request = context.Request;
            _response = context.Response;
            _application = context.Application;
            _cache = context.Cache;

    Then look at the Request/Response/etc.. properties and you'll likely see that it surfaces just those private fields. So, in short HttpContext is build earlier and passed to the page when the request is processsed and the page does expose some of it members directly so that you can use them without having to call explicitelyt HttpContext.Current (either for compatiblity as they used to be available everywhere which seems to make sense as you are processing after all an Http Request) or to enhance the discoverability of those members (else we would have seen tons of question about accessing request details from a page).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 9, 2015 1:55 PM

All replies

  • User753101303 posted

    Hi,

    Likely just as a convenience. This is quite at the core of a web application so they made it available directly from several classes. You can also look at http://referencesource.microsoft.com/

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 8, 2015 5:03 AM
  • User234527241 posted

    PatriceSc

    Hi,

    Likely just as a convenience. This is quite at the core of a web application so they made it available directly from several classes. You can also look at http://referencesource.microsoft.com/

    thanks but your answer is a general one and I am not OK with this type of answering

    my question has another part too , what is the difference  between them?

    Monday, June 8, 2015 6:34 AM
  • User-821857111 posted

    my question has another part too , what is the difference  between them?
    There is no difference between Page.Request. HttpContext.Request or HttpApplication.Request. The type is always HttpRequest and they all provide access to the same thing: the current Request object. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 8, 2015 9:24 AM
  • User753101303 posted

    There is no difference (as you can see by looking at the source code available at http://referencesource.microsoft.com)

    Monday, June 8, 2015 11:30 AM
  • User234527241 posted

    There is no difference (as you can see by looking at the source code available at http://referencesource.microsoft.com)

    I found this thread , if I understand it correctly , it implies that there are some differences
    http://stackoverflow.com/questions/5547989/difference-between-httpcontext-request-and-request

    I have another issue :
    I am curios that how its possible for us to using AIOs without object instantiation ?
    what is your idea? which technique is used for achieving that ?

    Monday, June 8, 2015 1:28 PM
  • User-821857111 posted

    if I understand it correctly , it implies that there are some differences

    It depends on what you mean by "difference". To all practical intents, the value is the same thing. They are of course different in that they are properties of different objects. But that is self-evident.

    how its possible for us to using AIOs without object instantiation ?
    Static properties are not associated with an instance of an object. https://msdn.microsoft.com/en-us/library/79b3xss3.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 8, 2015 3:05 PM
  • User234527241 posted

    sia.mak

    if I understand it correctly , it implies that there are some differences

    It depends on what you mean by "difference". To all practical intents, the value is the same thing. They are of course different in that they are properties of different objects. But that is self-evident.

    sia.mak

    how its possible for us to using AIOs without object instantiation ?

    Static properties are not associated with an instance of an object. https://msdn.microsoft.com/en-us/library/79b3xss3.aspx

    sorry , I don't understand you , when you say "Static properties are not associated with an instance of an object", all of the AIOs are Instance properties not static .

    in other hand , If you refer to the documentation   it Implies that Asp.net in the background produces an Instance of the related class.

    I wanted to know the details of this procedure in terms of page life cycle and the pipeline architecture of Asp.net.

    the key point is in this procedure , then it would be clear why Asp.net designers decided to add AIOs in different places as you said for "convenience" or something else.                        

    Tuesday, June 9, 2015 12:37 PM
  • User753101303 posted

    For example look at http://referencesource.microsoft.com/#System.Web/UI/Page.cs

    You'll see for example :

     private void SetIntrinsics(HttpContext context, bool allowAsync) {
            _context = context;
            _request = context.Request;
            _response = context.Response;
            _application = context.Application;
            _cache = context.Cache;

    Then look at the Request/Response/etc.. properties and you'll likely see that it surfaces just those private fields. So, in short HttpContext is build earlier and passed to the page when the request is processsed and the page does expose some of it members directly so that you can use them without having to call explicitelyt HttpContext.Current (either for compatiblity as they used to be available everywhere which seems to make sense as you are processing after all an Http Request) or to enhance the discoverability of those members (else we would have seen tons of question about accessing request details from a page).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 9, 2015 1:55 PM