Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6686645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:11:44+00:00 2026-05-26T05:11:44+00:00

Is there any in-framework way to prevent Cross Site Request Forgery (CSRF) within ASP

  • 0

Is there any in-framework way to prevent Cross Site Request Forgery (CSRF) within ASP .NET 4.0 Web forms based websites (not MVC)? I do see the framework generate __EVENTVALIDATION and __VIEWSTATE hidden form fields and I’ve encrypted them via machineKey and viewStateEncryptionMode=”Always” in my web.config. However, it’s not clear if they can actually prevent CSRF attacks. I tested a cross posting (via PostBackUrl in the form’s asp:Button) form where I modified the __VIEWSTATE, __EVENTVALIDATION and __PREVIOUSPAGE (extra for cross posts) hidden, encrypted form fields and the other sensitive form fields still reached my code-behind processing block. I was expecting the framework to detect the modified encrypted fields and throw up an error. FYI, I saved the aspx as an .html, changed those hidden form fields and re-used the form (now in .html) to simulate an attacker. So I could still post to my sensitive form/fields because (start speculation) .html files don’t go through the ASP.NET processing engine? (/end speculation)

If no such in-framework mechanism exists, are there any code snippets for quick prototyping/usage? I can easily create a per-user unique identifier by hashing the user ID and even set a form hidden variable for that c# variable. But the ASP.NET 4.0 mechanics of

  • Also setting that c# variable as a cookie

and

  • Checking if the cookie value == form value on subsequent requests (for validity)

is unclear to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:11:45+00:00Added an answer on May 26, 2026 at 5:11 am

    I don’t know how to do it in the framework, but you can do it yourself easier than your post suggests.

    You don’t need to set the cookie value. Its just how the mvc framework does it as an optimization\ to allow the server to be stateless. All you need to do to pick some random ( to an attacker) value and add it as a hidden field in your form. When you get the data back, verify that that value is in the form. Don’t just hash the userid, hash the userid and some secrete random value. That way the attacker can’t compute the hidden value if she knows a user id.

    Because the same origin policy prevents attacker.com from reading the markup for your site, they can’t read the hidden value. Thus the CSRF post they make, while having your cookie ( and hence the view state), won’t have that value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any framework/library for using ASP.NET Membership Provider with confirmation email, something ready
Is there any way to validate using DataAnnotations in WPF & Entity Framework?
Is there any upnp framework for CF .NET? There is mono.upnp source but it
Are there any advantages compiling for .NET Framework 3.5 instead of 2.0? For example
Is there any class in the .NET framework that can read/write standard .ini files:
is there any ready to go solution within the microsoft framework, regarding conversion of
Is there any way I can send an email, like any frameworks or something.
Is there any framework for querying XML SQL Syntax, I seriously tire of iterating
Is there any framework that would allow me to integrate paypal with twitter, such
Is there any open source collection framework, written in ActionScript that would emulate HashMap,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.