android - ASP.NET MVC4 Web API & Session variables -


in asp.net mvc4 project, using apicontrollers serve both web clients , mobile clients. secure web services, using [authorize] annotation. now, web client working fine. however, when tend invoke web api mobile application (e.g. android), got error. when looked @ code snippet:

   [authorize]     public list<double> getsomeinfo(int param1, string param2)         {            user user = sessiondata.currentuser;            // using user.userid            // ....          } 

session data hold user connected properties when connected web app. in case of mobile clients, session data null. so, there appropriate method resolve problem. in opinion, think userid should provided parameter web api may need achieve treatment. think ?

you talking 2 different things :

  • session

as darrel said, web api not design support asp.net session. http , rest services stateless – , result each http request should carry enough information itself recipient process in complete harmony stateless nature of http. so, not rely on session variables, add more paramters in request. of course, there way use session in web api, suggest to use it.

  • authentication

because working paramaters ( such userid, accountid, ...) not secure, have use authentication , authorization. highly suggest read security section in asp.net web api web site. web api support many authentications (basic, oauth, windows, custom, ...). have choose best you.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -