Linked Questions

Popular Questions

HttpResponseMessage not working in Web Api (.NET 4.5)

Asked by At

I read and tried to use the code from that page:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Http.Filters;
using System.Web.Http.Controllers;

public class RequireHttpsAttribute : AuthorizationFilterAttribute
    public override void OnAuthorization(HttpActionContext actionContext)
        if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps)
            actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden)
                ReasonPhrase = "HTTPS Required"

When I build I don't get an error, but runtime gives this error:

CS0012: The type 'System.Net.Http.HttpRequestMessage' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net.Http, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

I have got a reference to System.Net.Http in my references folder of my project. If I look at it's properties, it says Version and Runtime Version 4.0.30319. My project properties says target framework is .NET 4.5.

My IntelliSense in VS2013 Express also doesn't want to pick up anything to do with HttpResponseMessage or HttpRequestMessage.

I've tried removing the reference and re-adding it, but to no avail.

Any help would be tremendously appreciated.

Related Questions