Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy would a custom MVC3 action filter work on one controller action but not on another?
    primarykey
    data
    text
    <p>Here's the situation. I've got a single action filter that I'm using in two different controllers. The action filter is defined as: </p> <pre><code>public class ValidSubmissionAttribute : FilterAttribute, IActionFilter { public void OnActionExecuted(ActionExecutedContext filterContext) { } public void OnActionExecuting(ActionExecutingContext filterContext) { var controller = filterContext.Controller; var session = filterContext.HttpContext.Session; var isValid = controller.TempData["IsValid"]; if (isValid == null || !(bool)isValid) { SharedUtilities.LogOutUser(session, controller.ViewData.ModelState); filterContext.Result = SharedUtilities.GetThankYouRedirect(); } } } </code></pre> <p>When I invoke the Attribute in one controller, like this:</p> <pre><code> [HttpPost] public ActionResult DoSomething(string button, Model data) { try { if (ModelState.IsValid) { TempData["IsValid"] = Request.Form["ValidRequest"] == Session.SessionID; Session["VerifyDoingSomethingData"] = data; return RedirectToAction("VerifyDoingSomething"); } } catch (Exception ex) { } } [ValidSubmission] public ActionResult VerifyDoingSomething() { ViewData.Model = Session["VerifyDoingSomethingData"]; return View("VerifyDoingSomething"); } </code></pre> <p>it functions as expected. However, when I call it from a different controller, like this:</p> <pre><code> [HttpPost] public ActionResult Index(string button, Model data) { try { if (ModelState.IsValid) { TempData["IsValid"] = Request.Form["ValidRequest"] == Session.SessionID; Session["ViewModel"] = data; return RedirectToAction("VerifyCancellation"); } } catch (Exception ex) { } } [ValidSubmission] public ActionResult VerifyCancellation() { ViewData.Model = Session["ViewModel"]; return View("VerifyCancellation"); } </code></pre> <p>the attribute doesn't run at all. My breakpoint in the OnActionExecuting method doesn't get hit.</p> <p>If I had to guess, I'd say there was some difference in the controllers or in the action methods, but they appear to be functionally similar. Any insights? Why would I be seeing such different behavior?</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.
    1. This table or related slice is empty.
    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