添加一个错误信息给视图模型基础上,ASP.NET MVC控制器属性 [英] Adding an error message to the view model based on controller attribute in ASP.NET MVC

查看:101
本文介绍了添加一个错误信息给视图模型基础上,ASP.NET MVC控制器属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个授权自定义属性我控制器,它的细节可以<一href="http://stackoverflow.com/questions/4342271/asp-net-mvc-forms-authorization-with-active-directory-groups/4383502#4383502">viewed这里。

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.

任何想法?

推荐答案

对于那些谁正在寻找的答案,这里就是我最后做的:

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);
}

这篇关于添加一个错误信息给视图模型基础上,ASP.NET MVC控制器属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆