如何将SSL添加到登录验证码? [英] how to add SSL to login authentication code?

查看:89
本文介绍了如何将SSL添加到登录验证码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写信寻求帮助,如何在我的网络API中添加SSL。我是否需要在下面的基本身份验证类中添加一些额外的方法:



I am writing to seek help, in how can I add SSL to my web api. Would I need to add some extra methods to the basic authentication class below:

string[] credentials = Encoding.ASCII.GetString(Convert.FromBase64String(authValue.Parameter)).Split(new[] { ':' });
            if (credentials.Length != 2 || string.IsNullOrEmpty(credentials[0]) || string.IsNullOrEmpty(credentials[1]))
            {
                //return Unauthorized(request);
                var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(string.Format("access denied")),
                };
            }
            ClaimRole user = repository.trial(credentials[0], credentials[1]);
            ClaimRole user2 = repository.unlim(credentials[0], credentials[1]);
                if (user == null || user2 == null )
                {
                var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(string.Format("access denied")),
                };
            }
            else
            {
               IPrincipal principal = new GenericPrincipal(new GenericIdentity(user.Username, BasicAuthResponseHeaderValue), new string[] { user.role });
                //IPrincipal principal = new GenericPrincipal(new GenericIdentity(user.Username, BasicAuthResponseHeaderValue), null);
                Thread.CurrentPrincipal = principal;
                HttpContext.Current.User = principal;
            }

            return base.SendAsync(request, cancellationToken);
        }





请帮忙。谢谢。



Please help. Thanks.

推荐答案

这篇关于如何将SSL添加到登录验证码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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