ASP0015: Suggest using IHeaderDictionary properties
Value | |
---|---|
Rule ID | ASP0015 |
Category | Usage |
Fix is breaking or non-breaking | Non-breaking |
IHeaderDictionary properties are the recommended strategy for accessing headers.
IHeaderDictionary
properties are recommended for accessing headers. Accessing headers using an indexer as in the example below is not recommended.
var app = WebApplication.Create();
app.MapGet("/", (HttpContext context) => context.Request.Headers[""content-type""]);
app.Run();
To fix a violation of this rule, use the property specified in the analyzer message to access the header specified in the message or apply the associated codefix.
var app = WebApplication.Create();
app.MapGet("/", (HttpContext context) => context.Request.Headers.ContentType);
app.Run();
Do not suppress a warning from this rule.
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
ASP.NET Core feedback
ASP.NET Core is an open source project. Select a link to provide feedback: