1

I have created a console application.

I am trying to access Session variables and use HttpClient to make Api calls.

I am not able to get Session and HttpClient classes in the namespaces.

I have added the following packages.

<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net45" />

please let me know if i missed out any other package.I want to execute the below code.

I am getting error like:

httpClient is a type but is used like a method.

Here is my Code:

6
  • stackoverflow.com/questions/13209010/… Commented Aug 24, 2015 at 10:34
  • I see no reason how you would get that error on line 2 of your code unless you have incorrect capitalisation. For Session, there is no session in a console app so you will never be able to access that. Commented Aug 24, 2015 at 10:41
  • Even I add namespace also,I cannot use Session in Console app? Commented Aug 24, 2015 at 10:50
  • @ShekharPankaj - I am not able to access any property of HttpClient.I am getting error" HttpClient is a field but used like a method". Commented Aug 24, 2015 at 10:53
  • Try System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient(); instead. Commented Aug 24, 2015 at 11:06

1 Answer 1

2

Session isn't available to Console applications.
It's an ASP.net thing - it resides server side.

When you access Session in an ASP.net application, all you're really doing is accessing the Session ID from the cookie that is sent with the request. The server then retrieves the Session object from the session store (in memory, in db, etc...) and makes it available to the server side application.

Your console app has no knowledge (nor should it) of any of this Session stuff.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.