Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 AntiForgeryToken Issue
    primarykey
    data
    text
    <p>I am trying to implement AntiForgeryToken for my MVC3 Application. I am having a problem with AntiForgeryToken after setting FormAuthentication cookie. Here is a simple example which explains my problem. </p> <p>I have home controller with following action methods:</p> <pre><code>public class HomeController : Controller { public ActionResult Logon() { return View(); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult Logon(string userName, string password) { FormsAuthentication.SetAuthCookie(userName, false); return View("About"); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult About(FormCollection form) { return View("PageA"); } } </code></pre> <p>And here is my Logon and About views:</p> <p>Logon.cshtml:</p> <pre><code> @using (Html.BeginForm("Logon", "Home")) { @Html.AntiForgeryToken() &lt;label&gt; UserName :&lt;/label&gt; &lt;input name = "userName" type="text"/&gt; &lt;br /&gt; &lt;label&gt; Password :&lt;/label&gt; &lt;input name = "password" type="password"/&gt; &lt;br /&gt; &lt;br /&gt; &lt;input type="submit" value="LogOn" /&gt; } </code></pre> <p>About.cshtml</p> <pre><code>@using (Html.BeginForm("About", "Home")) { @Html.AntiForgeryToken() &lt;p&gt; This is conent of page About&lt;/p&gt; &lt;input name = "moreInfo" type="text"/&gt; &lt;input type="submit" value="SubmitAbout" /&gt; } </code></pre> <p>I have no problem on "Logon" post method. It is validating the antiforgerytoken and rendering About view. Interestingly, when I do post on "About" view I am getting error "A required anti-forgery token was not supplied or was invalid"</p> <p>could some one point out what I am doing wrong here?</p> <p>Appreciate your help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload