Represents an Entity-Tag header value.
Namespace: System.Net.Http.Headers
Assembly: System.Net.Http.dll
An entity-tag is a header name in HTTP used to provide an identifier for a version of a resource. The ETag header is returned by an HTTP server in response to a conditional HTTP request. The client can then use this ETag in subsequent requests to specify the version of the resource it has. If the resource has not changed, the server can return a 304 Not Modified status code. If the resource has changed, the server returns the updated resource. The EntityTagHeaderValue class provides a way to parse and manipulate Entity-Tag header values.
Initializes a new instance of the EntityTagHeaderValue class.
Initializes a new instance of the EntityTagHeaderValue class with the specified tag.
public EntityTagHeaderValue(string tag);
Initializes a new instance of the EntityTagHeaderValue class with the specified tag and weak indicator.
public EntityTagHeaderValue(string tag, bool isWeak);
These static methods are used to parse an Entity-Tag header string into an EntityTagHeaderValue object.
Parses a string into an EntityTagHeaderValue instance.
public static EntityTagHeaderValue Parse(string value);
Tries to parse a string into an EntityTagHeaderValue instance.
public static bool TryParse(string value, out EntityTagHeaderValue result);
Returns a string representation of the EntityTagHeaderValue.
public override string ToString();
The following code example demonstrates how to create and use an EntityTagHeaderValue object.
using System;
using System.Net.Http.Headers;
public class Example
{
public static void Main()
{
// Create an EntityTagHeaderValue
EntityTagHeaderValue etag = new EntityTagHeaderValue("\"abcdef-12345\"");
Console.WriteLine($"ETag: {etag}");
Console.WriteLine($"Is Weak: {etag.IsWeak}");
Console.WriteLine($"Tag Value: {etag.Tag}");
// Parse an ETag header
string headerString = "W/\"some-other-tag\"";
if (EntityTagHeaderValue.TryParse(headerString, out EntityTagHeaderValue parsedEtag))
{
Console.WriteLine($"Parsed ETag: {parsedEtag}");
Console.WriteLine($"Parsed Is Weak: {parsedEtag.IsWeak}");
Console.WriteLine($"Parsed Tag Value: {parsedEtag.Tag}");
}
else
{
Console.WriteLine($"Failed to parse ETag: {headerString}");
}
}
}