Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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# 使用Android 4.0 Chrome进行ASP.NET MVC基本身份验证_C#_Android_Asp.net Mvc_Basic Authentication - Fatal编程技术网

C# 使用Android 4.0 Chrome进行ASP.NET MVC基本身份验证

C# 使用Android 4.0 Chrome进行ASP.NET MVC基本身份验证,c#,android,asp.net-mvc,basic-authentication,C#,Android,Asp.net Mvc,Basic Authentication,我已经在我的MVC网站上设置了一个基本的身份验证ActionFilterAttribute,在开发过程中将其锁定,在我测试的所有浏览器(IE9+、Chrome、FF、iOS Safari)中都能100%工作,但当我在Android 4.0中加载Chrome时,它只是显示一个401访问被拒绝,从不要求我提供基本的身份验证凭据 这是我的OnAuthorization方法代码: public void OnAuthorization(AuthorizationContext filterCon

我已经在我的MVC网站上设置了一个基本的身份验证
ActionFilterAttribute
,在开发过程中将其锁定,在我测试的所有浏览器(IE9+、Chrome、FF、iOS Safari)中都能100%工作,但当我在Android 4.0中加载Chrome时,它只是显示一个401访问被拒绝,从不要求我提供基本的身份验证凭据

这是我的
OnAuthorization
方法代码:

    public void OnAuthorization(AuthorizationContext filterContext)
    {
        var controllerName = (filterContext.RouteData.Values["controller"] as string).ToLower();
        if (_controllersToIgnore.Contains(controllerName))
        {
            return;
        }

        bool credentialsMatch = false;
        var req = filterContext.HttpContext.Request;
        if (!string.IsNullOrEmpty(req.Headers["Authorization"]))
        {
            var cred = System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(req.Headers["Authorization"].Substring(6))).Split(':');
            var user = new { Name = cred[0], Pass = cred[1] };
            if (user.Name == Username && user.Pass == Password)
            {
                credentialsMatch = true;
            }
        }
        if (!credentialsMatch)
        {
            var res = filterContext.HttpContext.Response;
            res.StatusCode = 401;
            res.AddHeader("WWW-Authenticate", "Basic realm=\"\"");
            res.End();
            filterContext.Result = new EmptyResult();
        }
    }

奇怪的是,这个问题自行消失了,我什么也没做(很明显),只是停止了