4

I am getting the following error while writing the below code -

Error

'System.Net.Http.HttpRequestMessage' does not contain a definition for 'GetRequestContext' and no extension method 'GetRequestContext' accepting a first argument of type 'System.Net.Http.HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?)

Code

var context = actionContext.Request.GetRequestContext(); context.Principal = principal; 

I have referenced to the required library - System.Net.Http also but still the error is coming.

1
  • In Web API 2.0, there is a new HttpRequestContext class. Try just using, var context = Request.GetRequestContext(); in System.Web.Http. Commented Jan 12, 2015 at 17:32

2 Answers 2

3

In addition to referencing the System.Net.Http assembly, make sure you bring the namespace in scope:

using System.Net.Http; 
Sign up to request clarification or add additional context in comments.

Comments

1

You need to have the nuget package Microsoft.AspNet.WebApi.Core and then you can access extensions in System.Net.Http namespace such as request.GetRequestContext(), etc.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.