Dimitri
Dimitri

Reputation: 2858

WCF Check if the request was made securely

Baisicly the thing I wanna do is find out if the request to my wcf service was made securely. And I use the following code.

context = OperationContext.Current;
bool isSecure = context.IncomingMessageHeaders.To.Scheme == Uri.UriSchemeHttps;  

is this a proper way to do that ? If you don't understand what I mean and what I want to achieve I can provide more details.

Upvotes: 0

Views: 428

Answers (2)

Mike Goodwin
Mike Goodwin

Reputation: 8880

I guess you want to check because you are going to execute different logic depending on whether the connection was secure or not.

In this case, I would take a different approach. Rather than check in the service code and switch the control flow, you could consider implementing the different logical flows in different endpoint behaviors - configure one one for the HTTP endpoint and the other for HTTPS endpoint.

This feels like better encapsulation that the approach of checking the operation context and would likely be more testable.

Upvotes: 1

Yann39
Yann39

Reputation: 15719

You can check Request.IsSecureConnection

See MSDN documentation

Upvotes: 1

Related Questions