c# - Declare a single static variable that will be used by many WebMethod functions -


i have session variable need use on cs page many webmethod functions. if declare follows don't latest variable. gives me variable stored before last one. doing wrong?

public partial class uc_functions : mybasepage {     static string ucservice = httpcontext.current.session["ucservice"] string; ....  [webmethod] //1 [webmethod] //2 [webmethod] //3 

currently you're initializing variable once, when class first loaded. want have different value on each request.

rather having variable that, should have property or method. example:

private static string service {     { return (string) httpcontext.current.session["ucservice"]; } } 

or in c# 6:

private static string service => (string) httpcontext.current.session["ucservice"]; 

(as aside, i'd review .net naming conventions - class called uc_functions makes me shudder...)


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -