带参数的WebConfig redirectRoute在控制器中传递null

时间:2018-07-27 06:36:14

标签: asp.net security model-view-controller error-handling

我目前正在为403、404、500状态代码实现自定义错误页面。我在web.config中设置了自定义错误:

<customErrors mode="On" defaultRedirect="~/Error/Index/3">
    <error redirect="~/Error/Index/1" statusCode="403" />
    <error redirect="~/Error/Index/2" statusCode="404" />
    <error redirect="~/Error/Index/3" statusCode="500" />
  </customErrors>

在我的控制器中,我有这个:

public partial class ErrorController : Controller
{
    [Route("Error/{ErrorID?}", Name = "Error")]
    public virtual ActionResult Index(int? ErrorID)
    {
        switch (ErrorID)
        {
            case 1:
                Response.StatusCode = 200;
                ViewBag.Error = SharedResources.Index.PageNotFoundError;
                break;
            case 2:
                Response.StatusCode = 200;
                ViewBag.Error = SharedResources.Index.PageNotAuthorizedError;
                break;
            case 3:
                Response.StatusCode = 200;
                ViewBag.Error = SharedResources.Index.AdminError;
                break;
            default:
                Response.StatusCode = 200;
                ViewBag.Error = SharedResources.Index.AdminError;
                break;
        }
        return View();
    }
}

问题在于ErrorID始终为null,并且永远没有任何值。我在这里想念什么?

0 个答案:

没有答案