Is it ok to use HttpRequestMessage.properties in .net core 3.1?

Nishi-nishi 21 Reputation points
2021-12-21T22:36:00.037+00:00

Hi,
I'm using HttpRequestMessage properties property in order to pass auth type in the request so that the message habdler will generate the correct authorization heade (basic, jwt, etc...)
Is it good approach?

Another thing I saw the Properties marked as Obsolet "Use options instead"
But I cannot find the Options property, so I wandered since which version is obsolete? And is it safe to keep usinfg it in .net core 3.1?

Thaks

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,166 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,248 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,119 questions
0 comments No comments
{count} votes

Accepted answer
  1. Zhi Lv - MSFT 32,011 Reputation points Microsoft Vendor
    2021-12-22T08:36:58.867+00:00

    Hi @Nishi-nishi ,

    I'm using HttpRequestMessage properties property in order to pass auth type in the request so that the message habdler will generate the correct authorization heade (basic, jwt, etc...)
    Is it good approach?

    You can use the HttpRequestMessage properties to add the authorization header in the Asp.net core 3.1 application, it is OK. Refer to the official document: Make HTTP requests using IHttpClientFactory in ASP.NET Core.

    Another thing I saw the Properties marked as Obsolet "Use options instead"

    You may be viewing the latest version of the document, you can check the following screenshot, the document is for the .Net 6, but if you check the "Applies to" part, this property still applies to Asp.net core 3.1.

    159619-image.png

    If you want to view the .Net Core 3.1 version document, you can change the .Net Version or see this link.

    159597-image.png

    To the HttpRequestMessage.Options Property, we can see this property applies to Asp.net 5 and Asp.net 6, instead of Asp.net Core 3.1:

    159671-image.png


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion


0 additional answers

Sort by: Most helpful