Chiragkumar Thakar
Chiragkumar Thakar

Reputation: 3706

Not getting session value in angularjs file

I want to access asp.net(C#) session value in angularjs file, what should be the best way to access session value.

What i tried, but couldn't able to get it.

 $session.get(key) 

Upvotes: 3

Views: 2144

Answers (3)

C Rudolph
C Rudolph

Reputation: 622

Expanding on Michael's 2nd option "write a RESTful service to get some session information value"

One possible way to do this is

  1. Create and set your session object as usual
  2. Redirect the user to your html page with a query param "google.com?sm=1"
  3. Look for the "sm" query param in angularjs/javascript and make an api call that returns your session object

Upvotes: 0

Liviu Costea
Liviu Costea

Reputation: 3774

You need to do this through a server side controller, the session is stored on the server, while angular will run on the client. So you can make a Session controller to receive a key and to return in JSOn format the value from the Session.

Upvotes: 1

Michael
Michael

Reputation: 3104

ASP.NET is backend and Angular runs in the browser. ;-)

You have several options:

  1. write the session into a cookie (if not already done by ASP.NET) and read the value via the angular-cookies library

  2. write a RESTful service to get some session information value

  3. render the value into a hidden field and read it via jquery

Upvotes: 3

Related Questions