Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 针对引发的特定异常重定向web.config中的页面_C#_Asp.net Mvc_Web Config - Fatal编程技术网

C# 针对引发的特定异常重定向web.config中的页面

C# 针对引发的特定异常重定向web.config中的页面,c#,asp.net-mvc,web-config,C#,Asp.net Mvc,Web Config,我有一个MVC解决方案,它基于登录用户对某些URL进行授权 我在父控制器上使用了一个受保护的方法来解决这个问题,该方法检查用户是否是管理员。代码如下: [Authorize] public abstract class ConfigurationController<E> : Controller where E : IPersistentVM, new() { //SOME OTHER CODE RIGHT HERE protected ActionResult C

我有一个MVC解决方案,它基于登录用户对某些URL进行授权

我在父控制器上使用了一个受保护的方法来解决这个问题,该方法检查用户是否是管理员。代码如下:

[Authorize]
public abstract class ConfigurationController<E> : Controller where E : IPersistentVM, new()
{
    //SOME OTHER CODE RIGHT HERE
    protected ActionResult CheckPermission(string url, SPDCSS.Model.Rules.Enums.Permission.Permissions permission)
    {
        var user = Helper.GetLoggedInUser();
        if (user.UserTypeId == (int)SPDCSS.Model.Rules.Enums.UserType.UserTypes.Administrator)
        {
            return View(url);
        }
        throw new UnauthorizedAccessException("Access Denied.");
    } 
}

我想,问题可能出在我指定的状态码上,但我不知道该用什么。你知道问题出在哪里吗?

你在远程位置测试吗?不,我现在正在本地主机上测试。。。在远程位置上使用不同的状态代码?查看您的标签。模式是remoteonly。我删除了此行,但仍然无法工作=(更好的方法是对自定义错误使用application_error,主要是因为您将能够记录该错误并对其中的数据进行处理
namespace SPDCSS.Management.Web.Application.Controllers.Configuration
{
    public class ChartController : ConfigurationController<ChartVM>
    {
        public ActionResult Chart()
        {
            return CheckPermission("~/Views/Configuration/Chart.cshtml",M.Enums.Permission.Permissions.Chart);
        }
        //MORE CODE HERE... 
    }
}
<system.web>
    <customErrors mode="RemoteOnly" defaultRedirect="~/Views/Shared/Error.cshtml">
      <error statusCode="403" redirect="~/Views/Shared/UnauthorizedAccess.cshtml" />
    </customErrors>
    <!-- # some other code # -->
</system.web>