实时时,基本身份验证在IE或Chrome中无效 [英] Basic authentication not working in IE or Chrome when live

查看:68
本文介绍了实时时,基本身份验证在IE或Chrome中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



以下代码未在IE网络浏览器中授权用户名和密码,一旦我部署了web-api应用程序。我似乎无法弄清楚原因。我尝试使用fiddler调试live(在ftp上传时)身份验证,并且能够从不同的Web浏览器中提取下面的原始消息。



任何人都可以提供任何帮助,下面的回答是什么意思?



非常感谢



firefox:

Hello,

following code does not authorize username and password in IE web browser, once i have deployed the web-api application. I cannot seem to figure out the reason. I have tried debugging the live(when uploaded on the ftp)authentication using fiddler and was able to extract raw messages below, from different web browsers.

Could anyone please provide any assistance, into what the following response below mean?

Many Thanks

firefox:

GET http://xxxx.xxxx.com/api/values HTTP/1.1
Host: xxxx.xxxxx.com
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: __utma=160871039.470048631.1389004711.1389004711.1389004711.1; __utmc=160871039; __utmz=160871039.1389004711.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Connection: keep-alive





资源管理器:



explorer:

GET http://#####.######.com/api/values HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-GB
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; MDDCJS)
Accept-Encoding: gzip, deflate
Host: ####.#####.com
Cookie: __utma=160871039.1791605041.1363174995.1374568675.1374856696.5; __utmz=160871039.1363174996.1.2.utmcsr=bing|utmccn=(organic)|utmcmd=organic|utmctr=######; __qca=P0-637394059-1363174995765
Connection: Keep-Alive
Authorization: Negotiate TlRMTVNTUAABAAAAl4II4gAAAAAAAAAAAAAAAAAAAAAGAvAjAAAADw==
DNT: 1



<无线电通信/>



public class BasicAuthenticationMessageHandler : DelegatingHandler
    {
        private const string BasicAuthResponseHeader = "WWW-Authenticate";
        private const string BasicAuthResponseHeaderValue = "Basic";

        public IProvidePrincipal PrincipalProvider { get; set; }

        protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            AuthenticationHeaderValue authValue = request.Headers.Authorization;
            if (authValue != null && !String.IsNullOrWhiteSpace(authValue.Parameter))
            {
                Credentials parsedCredentials = ParseAuthorizationHeader(authValue.Parameter);
                if (parsedCredentials != null)
                {
                    Thread.CurrentPrincipal = PrincipalProvider
                        .CreatePrincipal(parsedCredentials.Username, parsedCredentials.Password);
                }
            }
            return base.SendAsync(request, cancellationToken)
                .ContinueWith(task =>
                {
                    var response = task.Result;
                    if (response.StatusCode == HttpStatusCode.Unauthorized
                        && !response.Headers.Contains(BasicAuthResponseHeader))
                    {
                        response.Headers.Add(BasicAuthResponseHeader
                                             , BasicAuthResponseHeaderValue);
                    }
                    return response;
                });
        }

        private Credentials ParseAuthorizationHeader(string authHeader)
        {
            string[] credentials = Encoding.ASCII.GetString(Convert
                                                                .FromBase64String(authHeader))
                .Split(
                    new[] { ':' });
            if (credentials.Length != 2 || string.IsNullOrEmpty(credentials[0])
                || string.IsNullOrEmpty(credentials[1])) return null;
            return new Credentials()
            {
                Username = credentials[0],
                Password = credentials[1],
            };
        }
}

推荐答案

浏览器只会将您发送的信息解释为HTML。

一般来说,浏览器相关的问题来自用CSS制作的设计。

但它们对于所有其他服务器相关的东西都是相同的,并对服务器上的所有数据做同样的事情。



从您的代码中可以看出,它在服务器端执行编码非常明显。

因此,它应该在每个浏览器上都能正常工作。 />


我想你还有其他一些问题,所以在Visual Studio中逐个调试所有浏览器的代码并尝试找到问题。
Browser will just interpret the information you send as HTML.
Generally, browser related issues comes for designs made with CSS.
But they would function the same for all other server related stuffs and do the same thing to all the data at server.

From your code, it is quite obvious that it performs coding at server end.
So, it should work the same on every browser.

I guess you have some other issues, so debug your code with all browsers one by one selecting in Visual Studio and try to find the issue.


这篇关于实时时,基本身份验证在IE或Chrome中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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