문제

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