MVC请求/ null返回404错误

时间:2016-11-15 17:28:50

标签: asp.net-mvc null http-status-code-404

除非你查看错误日志,否则我的MVC项目看起来效果很好。成功返回每个页面后,尝试加载site.example.com/null,我不知道为什么。这是Fiddler的片段:

enter image description here

它对用户没有影响,但很烦人。这是一个被调用的代码示例:

public class GuidanceController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

我在视图中没有任何异常,我没有必要改变RouteConfig。我有一个自定义授权类,如下所示:

namespace MyProj.Filters {
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]

public class MyProjAuthorizeAttribute : AuthorizeAttribute
{
    public AccessLvl[] AccessLvls;
    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
        AuthorizationClient authClient = new AuthorizationClient();
        var authorized = base.AuthorizeCore(httpContext);
        if (!authorized)
            return false;

        int intId = 0;
        string requestId = httpContext.Request.Path.Split('/').Last(); //get ID sent with new page
        string referrerId = httpContext.Request.UrlReferrer?.AbsolutePath.Split('/').Last(); //get ID sent with old page

        if (int.TryParse(requestId, out intId) != true) //prefer new ID, if available
            int.TryParse(referrerId, out intId); //else just use old id

        List<AccessLvl> userAccessLevels = authClient.GetAccessLevels((intId == 0) ? null : intId.ToString());

        foreach (AccessLvl level in AccessLvls)
        {
            if (userAccessLevels.Contains(level))
            {
                return true;
            }
        }

        return false;
    }

    protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
    {
        filterContext.Result = new RedirectToRouteResult(
            new RouteValueDictionary(
                new
                {
                    controller = "Error",
                    action = "Unauthorized",
                    urlReferrer = filterContext.RequestContext.HttpContext.Request.Url
                })
            );
    }
}

}

我在俯瞰什么?非常感谢任何想法。

0 个答案:

没有答案