This article is a mirror article of machine translation, please click here to jump to the original article.

View: 21264|Reply: 0

[ASP.NET] C# must modify this header workaround with the appropriate attributes or methods

[Copy link]
Posted on 3/14/2018 10:24:54 AM | | |
When the headers requests of the http protocol are set in the Asp.Net, the attributes defined by some protocols are already encapsulated, and the submission cannot be customized using the Add method.

When using the httpwebrequest and webrequest class in C#, if you try to set the header of the http request, whether you use the set method or the add method, for example, we set the referer property in the header:

request. Headers.Set("Referer", "itsvse.com");
request. Headers.Add("Referer", "itsvse.com");
will error: "This header must be modified with the appropriate attribute or method".

Reason: C# doesn't allow you to use the set and add methods to set such headers

C# already provides a dedicated attribute for such a header that you can use when modifying and setting this header.

The header name and corresponding attributes are set as follows:

Header       Set up
Accept       Accept property.
ConnectionSet by the Connection property and the KeepAlive property.
Content-LengthSet by the ContentLength property.
Content-TypeSetby the ContentType property.
ExpectSet by the Expect property.
Date       Set by the Date property.
HostHost property.
If-Modified-SinceSet by the IfModifiedSince property.
Range       Set by the AddRange method.
RefererSet by the Referer property.
Transfer-EncodingSet by the TransferEncoding property (the SendChunked property must be true).
User-AgentUserAgent property


As shown in the table above, we modify the Referer, all you need to do is

request. Referer = "itsvse.com";



More examples








Previous:asp.net IHttpModule interface is explained in detail
Next:asp.net Implement the reverse proxy function [Source code]
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com