I wonder if you have noticed this attribute before. Here we will discuss the role of this attribute and how to use it in the future!
Let's take a look at this property: (Note: This property is added in. NET 2.0 !)
1. Its namespace is system. Web. configuration.
2.ProgramSet: system. Web (in system. Web. dll)
3. Class: pagessection
I have a general understanding of this attribute above. Next we will analyze it in detail. This attribute is used to verify the input of client users, it is used to verify whether there are dangerous characters in user input. The default value of this attribute is true. Microsoft does this to improve the security of the Asp.net program, therefore, even if many programmers do not know how to defend against hacker attacks, some default attributes of Asp.net and other content have been controlled for security. This is why the Asp.net program is relatively secure!
Since the default value of this attribute is true, and the Asp.net page is frequently resent, if there is no user interaction, Will Asp.net be strictly adjusted every time, in this way, the execution time of the system may be lost. As for: If there is no client interaction, Will Asp.net verify that this is a problem for Microsoft engineers? For us, if there is no client interaction, I feel that this attribute should be set to false, so no matter how Microsoft engineers design it, it has no impact on our program itself!
However, when users need to interact with each other, we need to use its default value. However, things may not be as simple as we think, nor perfect, when a user uses some HTML editors, there are <xxxxxxx> and other such characters in the submitted characters. This requires the programmer to disable the validaterequest attribute, in this case, how can we control the security performance of the Asp.net page?
Of course, we can filter all dangerous characters in this area, which may improve security, but we prevent omissions in user input, this leads to security issues. In turn, we can consider how many special characters we need to submit and then escape or replace the special characters we have submitted, in this way, we can set the validaterequest attribute to true, which not only solves the security problem of the program but also meets our needs!
Sometimes, when interacting with users, users may inevitably enter special characters, because the value of validaterequest we set is true, so the page will not give any prompt, directly output a large page of error information, which may lead to users' misunderstanding. They may think that the website is faulty and the user cannot think that he has entered invalid characters! What should we do in this case?
Fortunately, Microsoft engineers provided another page_error event in the page, so that we can use it to capture exceptions.CodeAs follows:
Protected void page_error (Object sender, eventargs E)
{
Exception EX = server. getlasterror ();
If (ex is httprequestvalidationexception)
{
Response. Write ("the characters you entered have invalid characters! ");
Server. clearerror ();
}
}
With this prompt, you may not know how many times better the user experience will be!
Because the younger brother was recently working on a website background, he encountered this small problem. I can see that the above is well written, so let's go.
This article from http://tech.ddvip.com/2009-03/1235963787110082.html