Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/aspnetwebstack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/System.Web.Mvc/ValidateAntiForgeryTokenAttribute.cs')
-rw-r--r--src/System.Web.Mvc/ValidateAntiForgeryTokenAttribute.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/System.Web.Mvc/ValidateAntiForgeryTokenAttribute.cs b/src/System.Web.Mvc/ValidateAntiForgeryTokenAttribute.cs
new file mode 100644
index 00000000..b948a0b0
--- /dev/null
+++ b/src/System.Web.Mvc/ValidateAntiForgeryTokenAttribute.cs
@@ -0,0 +1,40 @@
+using System.Diagnostics;
+using System.Web.Helpers;
+
+namespace System.Web.Mvc
+{
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
+ public sealed class ValidateAntiForgeryTokenAttribute : FilterAttribute, IAuthorizationFilter
+ {
+ private string _salt;
+
+ public ValidateAntiForgeryTokenAttribute()
+ : this(AntiForgery.Validate)
+ {
+ }
+
+ internal ValidateAntiForgeryTokenAttribute(Action<HttpContextBase, string> validateAction)
+ {
+ Debug.Assert(validateAction != null);
+ ValidateAction = validateAction;
+ }
+
+ public string Salt
+ {
+ get { return _salt ?? String.Empty; }
+ set { _salt = value; }
+ }
+
+ internal Action<HttpContextBase, string> ValidateAction { get; private set; }
+
+ public void OnAuthorization(AuthorizationContext filterContext)
+ {
+ if (filterContext == null)
+ {
+ throw new ArgumentNullException("filterContext");
+ }
+
+ ValidateAction(filterContext.HttpContext, Salt);
+ }
+ }
+}