Search code examples
c#.netasp.net-mvccontent-type

"application/json" constant in .NET framework


I've just declared a constant for the "application/json" content type in one of my classes.

public const string JsonContentType = "application/json";

I'm not sure it is a good practice.

Does .NET framework have a predefined const for "application/json"?


Solution

  • See Newer Answer. This answer is now inaccurate.

    While there are some MIME constants defined in MediaTypeNames (see here), there no constant for "application/json".

    Putting additional content types in a shared const is probably best practice, better than defining them in string literals a million times throughout your code at least.

    Plus it gives you the flexibility of using new/custom MIME types, which a specific .NET version might not have.