我想捕获错误代码:401,并将用户发送到特定视图 [英] I want to capture the error code: 401, and send the user to specific view

查看:72
本文介绍了我想捕获错误代码:401,并将用户发送到特定视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨,,全部

我想捕获错误代码:401(用户未经授权,我想将用户发送到特定视图)...



请查看我的代码,并提前告诉我... thnx ...



我尝试了什么:



这是我的Web.config文件

 <   customErrors     mode   =  >  
< 错误 statusCode = 401 重定向 = 〜/ Home / SecureMethod / >



这是我的行动方法,我用[授权]过滤器标记了它

 [授权] 
public ActionResult SecureMethod()
{
return View();
}



这是我的观点



 @ { 
ViewBag.Title =SecureMethod;
}
< h2 > 您无权查看此页面...请联系admin !! < / h2 >

解决方案

您正在尝试显示如果用户未被授权访问某些资源,则会出现错误,但您的错误页面需要授权用户,否则不会显示(并且可能会生成401错误)...

从您的操作中删除[授权] ...

Hi,, all
I want to capture the error code: 401 (user not authorized and i want to send the user to a particular View)...

please review my code and suggest me..thnx in advance...

What I have tried:

This is my Web.config file

<customErrors mode="On">
  <error statusCode="401" redirect="~/Home/SecureMethod"/>


This is my Action Method, i've labeled it with [Authorize] filter

[Authorize]
public ActionResult SecureMethod()
{
  return View();
}


This is my View

@{
  ViewBag.Title = "SecureMethod";
}
<h2>You are not authorized to view this page...please contact admin!!</h2>

解决方案

You are trying to display an error in case user not authorized to access some resource, but your error page requires authorized user, otherwise it does not display (and probably generates an 401 error)...
Remove [Authorize] from your action...


这篇关于我想捕获错误代码:401,并将用户发送到特定视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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