Buradaki yazımda web api metodlarımıza gelen tüm isteklere cevap dönüyorduk.
Buradaki yazımda ise önceden tanımladığımız iplerin web api metodlarına erişmesinden bahsettim. Bu yazımdaki ise web api sadece https üzerinden gelen isteklere nasıl cevap verir ondan bahsedeceğim.

Öncelikle projemize sağ tıklayıp Add -> Class deyip Class ismine CustomHttpsAttribute yazıyoruz.
Ardından aşağıdaki kod parçasını oluşturduğumuz class içine koplayaıp yapıştıralım.

public class CustomHttpsAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
if (!String.Equals(actionContext.Request.RequestUri.Scheme, "https", StringComparison.OrdinalIgnoreCase))
{
actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)
{
Content = new StringContent("HTTPS protokolü ile istek yapmalısınız.")
};
return;
}
}
}

Son olarak Global.asax içindeki Application_Start() metoduna

GlobalConfiguration.Configuration.Filters.Add(new CustomHttpsAttribute());

kod parçasını ekliyoruz. Çalıştırdığımızda web api sadece https protokolü üzerinden gönderilen isteklere cevap dönecektir.