ServiceStack Request Filter to Require Secure Connection

This code snippet provides a Request Filter to make sure your ServiceStack services are being called via HTTPS.  If not, it returns a 403 code.

public class SecureRequestFilterAttribute : Attribute, IHasRequestFilter{    public IHasRequestFilter Copy()    {        return this;    }    public int Priority    {        //        // By setting priority to -100, this filter will be applied first.        get { return -100; }    }    public void RequestFilter(IHttpRequest req, IHttpResponse res, object requestDto)    {        //        if (!req.IsSecureConnection)        {            res.StatusCode = (int)HttpStatusCode.Forbidden;            res.Close();        }    }}


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s