0

i want to set session variables from web api controller and access it into App.js method is there any way to access like that ?

i'd already tried using :-

HttpContext.Current.Session

but i'm not able to set and access session variables globally and access it on second page ...

Nimesh khatri
  • 763
  • 12
  • 29
  • [Answered here](http://stackoverflow.com/questions/9594229/accessing-session-using-asp-net-web-api) - though I would carefully consider whether you want to hold state in session, as stated in answers in the link. – Prabu Aug 05 '15 at 09:15
  • Thanks for your opinion but i want to set session variable in my controller something like Session['variable'] = something and access it on second page something like session['variable'].toString() ...Getting my point ??? – Nimesh khatri Aug 05 '15 at 09:23
  • Can App.js send a request to the Web API to get these variables? Could you give an example of a variable you want to pass between the two? – Russ Penska Aug 05 '15 at 10:56

1 Answers1

1

There is no session mechanisim on web api beacuse it is against restfull idea.

If you need to store data like session you may consider to use

  1. Http Cookies http://www.asp.net/web-api/overview/advanced/http-cookies

  2. Encrypted tokens which has the information you want to store.

  3. Use an MVC application like web api (playing with routes)

    Don't store sensitive data and use HTTPS

Community
  • 1
  • 1
zapoo
  • 1,548
  • 3
  • 17
  • 32