Click here to Skip to main content
15,748,615 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

C#
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.
Posted
Comments
ZurdoDev 25-Mar-14 12:51pm    
It depends on what you mean. SSL can be implemented by installing a certificate on the server and then the only thing you change in code is changing http to https. However, some sites require that you attach an x509 certificate in your code. That's a different story.
miss786 25-Mar-14 12:55pm    
Hi, Thank you for your response. Is their link or tutorial i can follow, to implement this SSL feature into my server. Apology for unclear explanation, as I just read upon SSL being security feature of api feeds.
many thanks for your help.
ZurdoDev 25-Mar-14 13:04pm    
In IIS you can just import a certificate and require SSL. The IIS help has that. It's not a code issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900