Question

I made an annotation for pages that require logging in, if the user is not logged in it will be redirected to the login page. I would also like to add an error which requires tempdata to view the error. Otherwise i have to set an message and check if the user is logged in every controller.

So my question is if it's possible to set a tempdata in a non controller, if it's possible how could i achieve this?

Was it helpful?

Solution

Do you mean you made a action filter for those pages? If so, you can access tempdata in the filter context.

public void OnActionExecuting(ActionExecutingContext filterContext)
{
    filterContext.Controller.TempData
            ...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top