Click here to Skip to main content
15,914,221 members
Articles / Web Development / ASP.NET
Tip/Trick

The Power Of ViewState in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.17/5 (6 votes)
19 Mar 2012CPOL 33.7K   12  
about the one-click attack
This is an old version of the currently published tip/trick.

Introduction

one of my client server has been attacked by the way calls ” One-Click Attack “.
do you know what is one-click attack?
I don’t want to annoy you with a long description of this kind of attack, so I make it short!
one-click attack:
a hacker creates HTML that includes a form and a link,which,when clicked, submit the form to the server being attacked. hacker use it to spam the target site.

solution

in one-click attack they use third parties. like the emails that so familiar like: ” click here to claim your prize “.
you can set the ViewStateUserKey property on your pages.and it will stored in ViewState.
if page is postback, the runtime check the ViewState to make Sure It’s equal to the current ViewStateUserKey.

here is an example of the code that can solve your problem:
C#
protected void Page_Init(object sender, EventArgs e)
{
this.ViewStateUserKey = Request.UserHostAddress;
}  

and now the attackers can’t copy your hidden field and use it in one-click attack!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Iran (Islamic Republic of) Iran (Islamic Republic of)
Taha has started programming at the age of 16 and he has taken an avid interest in Microsoft technologies. He professionally works on ASP.NET and C#. Mainly, He lives for getting the world into codes and follows this aspiration in a third world country with lack of facility and support. He never gives up seeking success and competence.

Comments and Discussions

Discussions on this specific version of this article. Add your comments on how to improve this article here. These comments will not be visible on the final published version of this article.