Using Tempdata in a class

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
            ...
}
链接地址: http://www.djcxy.com/p/74434.html

上一篇: 以编程方式/动态排除ActionFilter

下一篇: 在课堂中使用Tempdata