HttpContext.Features vs HttpContext.Items In Asp.Net Core

后端 未结 2 976
我在风中等你
我在风中等你 2021-02-08 10:02

What is the differences between these two Properties?

I can use HttpContext.Items instead of HttpContext.Features to share data

2条回答
  •  失恋的感觉
    2021-02-08 10:37

    HttpContext.Items is designed to share short-lived per-request data, as you mentioned.

    HttpContext.Features is designed to share various HTTP features that allow middleware to create or modify the application's hosting pipeline. It's already filled with several features from .NET, such as IHttpSendFileFeature.

    You should use HttpContext.Items to store data, and HttpContext.Features to add any new HTTP features that another middleware class might need.

提交回复
热议问题