Click here to Skip to main content
15,126,498 members
Articles / Web Development / ASP.NET
Posted 19 Mar 2012


12 bookmarked

The Power of ViewState in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.17/5 (6 votes)
7 Sep 2012CPOL
How to prevent one-click attacks.


One of my client servers was attacked by an 'One-Click Attack'. Do you know what an one-click attack is? I don’t want to annoy you with a long description of it, so I will make it short! An one-click attack is when a hacker creates HTML that includes a form and a link which, when clicked, submits the form to the server being attacked. The hacker use it to then spam the target site.


In one-click attacks they use third parties. Like emails with content that looks familiar like: "click here to claim your prize". You can set the ViewStateUserKey property on your pages and it will be stored in ViewState. If the page is postback, the runtime checks the ViewState to make sure it’s equal to the current ViewStateUserKey.

Here is an example of a code that can solve your problem:

protected void Page_Init(object sender, EventArgs e)
  this.ViewStateUserKey = Request.UserHostAddress;

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


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


About the Author

taha bahraminezhad Jooneghani
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

GeneralMy vote of 1 Pin
CoolVini27-Dec-13 5:18
MemberCoolVini27-Dec-13 5:18 
GeneralRe: My vote of 1 Pin
taha bahraminezhad Jooneghani11-Nov-14 21:28
Membertaha bahraminezhad Jooneghani11-Nov-14 21:28 
GeneralRe: My vote of 1 Pin
CoolVini21-Nov-14 6:48
MemberCoolVini21-Nov-14 6:48 
Questionone click attack Pin
bhargavpp17-Sep-12 20:31
Memberbhargavpp17-Sep-12 20:31 
AnswerRe: one click attack Pin
taha bahraminezhad Jooneghani17-Sep-12 23:19
Membertaha bahraminezhad Jooneghani17-Sep-12 23:19 
GeneralRe: one click attack Pin
bhargavpp18-Sep-12 0:41
Memberbhargavpp18-Sep-12 0:41 
AnswerRe: one click attack Pin
taha bahraminezhad Jooneghani18-Sep-12 1:11
Membertaha bahraminezhad Jooneghani18-Sep-12 1:11 
GeneralRe: one click attack Pin
bhargavpp18-Sep-12 1:14
Memberbhargavpp18-Sep-12 1:14 
QuestionNice Article Pin
kkankala7-Sep-12 6:16
Memberkkankala7-Sep-12 6:16 
AnswerRe: Nice Article Pin
taha bahraminezhad Jooneghani8-Sep-12 10:21
Membertaha bahraminezhad Jooneghani8-Sep-12 10:21 
GeneralNice Pin
sund7wells20-Mar-12 0:54
Membersund7wells20-Mar-12 0:54 
GeneralRe: Nice Pin
taha bahraminezhad Jooneghani20-Mar-12 10:24
Membertaha bahraminezhad Jooneghani20-Mar-12 10:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.