In my MVC 3 project i have a login page that uses the anti-forgery logic built into MVC 3.
On Firefox & Opera it works just fine, but on IE I get this:
A required anti-forgery token was not supplied or was invalid.
I'm really stumped on why only IE suffers this, I checked the cookie settings and they are set the same as the other browsers so I'm at a lost here.
When I use the anti forgery code, I use both a SALT and the domain check (which shouldn't matter but worth telling).
Here is the view code:
@model login.Models.LogOnModel
@{
ViewBag.Title = "Log On";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"> </script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//focus on form.
$("#UserName").focus();
});
</script>
@using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { @class = "form login" })) {
@Html.AntiForgeryToken("!@#Hq4(", ViewBag.AppDomain, "/")
<div id="box">
<h1>Login</h1>
Please enter your username and password. @Html.ActionLink("Register", "Register") if you don't have an account.
<div class="block" id="block-login">
<h2>
Login Form</h2>
<div class="content login">
@Html.ValidationSummary(true)
<div class="group buffer">
<div class="left">
<label class="label right">
@Html.LabelFor(m => m.UserName)</label>
</div>
<div class="right">
@Html.TextBoxFor(m => m.UserName, new { @class = "text_field" })
@Html.ValidationMessageFor(m => m.UserName)
</div>
</div>
<div class="group buffer">
<div class="left">
<label class="label right">
@Html.LabelFor(m => m.Password)</label>
</div>
<div class="right">
@Html.PasswordFor(m => m.Password, new { @class = "text_field" })
@Html.ValidationMessageFor(m => m.Password)
</div>
</div>
<div class="group buffer">
<div class="left">
<label class="label right">
@Html.LabelFor(m => m.RememberMe)</label>
</div>
<div class="right">
@Html.CheckBoxFor(m => m.RememberMe)
</div>
</div>
<div class="group navform buffer">
<div class="right">
<button class="button" type="submit">
<img src="@Url.Content("~/Content/images/icons/key.png")" alt="Save" />
Login
</button>
</div>
</div>
</div>
</div>
</div>
}
ViewBag.AppDomain is a value from web.config for easy setting during testing and production usage.
If I remove the domain and path portion from the antiforgery tag, it works just fine. So one of those two must be the problem.
POST
request is sending the AntiForgery cookie back? – TrophoplasmF12
on your keyboard. Alternatively use Firebug Lite – Trophoplasm