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?

有帮助吗?

解决方案

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
            ...
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top