Has Microsoft created a class full of constants for the standard HTTP header names or will I have to write my own?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- MVC-Routing,Why i can not ignore defaults,The matc
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
- Add to htmlAttributes for custom ActionLink helper
Request Headers
Response Headers
Microsoft created enums for the Request and Response Headers.
Take a look at the following:
HttpResponseHeader
HttpRequestHeader
They have them in HttpKnownHeaderNames but unfortunately that class is internal. I opened an issue for it: https://github.com/dotnet/corefx/issues/10632.
To expand on Jed's answer.
The
HttpResponseHeader
andHttpRequestHeader
enumerations can be used as your constants when using theWebHeaderCollection
.WebHeaderCollection
contains indexer properties that accept these enumerations.You can use either a string or one of the enumerations to get and set the header value, and mix it up as well within you code.
Example LinqPad script:
If you're using .NET Framework (not .NET Core), you can create an extension method to properly format the
System.Net.HttpRequestHeader
enum:Usage:
There are some available in the
Microsoft.Net.Http.Headers
nuget package. In my asp.net core project it was already installed.Example usage:
var value = request.Headers[Microsoft.Net.Http.Headers.HeaderNames.IfNoneMatch]
Might be what some are looking for?