3

I have a custom attribute for authorization on my controller, the details of which can be viewed here.

If this custom attribute returns false, it returns to the login screen. I want to add a error to my model for the login screen if the attribute returns false.

Any ideas?

1

2 Answers 2

5

For those who are looking for the answer, here is how I ended up doing it:

protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
   if (filterContext.HttpContext.User.Identity.IsAuthenticated)
   {
      var result = new ViewResult();
      result.ViewName = "NotAuthorized";
      result.MasterName = "_Layout";
      filterContext.Result = result;
   }
   else
      base.HandleUnauthorizedRequest(filterContext);
}
Sign up to request clarification or add additional context in comments.

Comments

0

Look at the TempData feature. Basically, it is similar to ViewData, but lives to the next request (using session). So, store your model error here (wrap it up appropriately if needed) and look for it after redirect in login page action.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.