Sunday, July 8, 2012

Keyword 'this' is not valid in a static property, static method, or static field initializer this.Page.User.Identity.Name

[WebMethod] is static and if the User.Identity.Name is used this error "Keyword 'this' is not valid in a static property, static method, or static field initializer" is thrown


Reason being this.Page.User.Identity is non static and usage is not valid. 
Instead using " HttpContext.Current.User.Identity.Name " will resolve the error since current is static. 


ex
someVariable = someMethodArgument(HttpContext.Current.User.Identity.Name);