The name "HttpContext" does not exist in the current context

I am trying to convert some vb.net to C #, but I am getting errors. At the moment, I get an error in the name.

Problem line:

string[] strUserInitials = HttpContext.Current.Request.ServerVariables("LOGON_USER").Split(Convert.ToChar("\\")); 

Does anyone know why this is happening?

I am working on a web service (asmx file).

I have the following at the top of the code:

 using System.Web; using System.Web.Services; using System.Web.Script.Services; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; 
+6
source share
4 answers

You need [] instead of ():

 string[] strUserInitials = System.Web.HttpContext.Current.Request.ServerVariables["LOGON_USER"].Split(System.Convert.ToChar(@"\")); 
+11
source

You need to access System.Web and import the System.Web namespace:

 using System.Web; 

I would not use Convert at all:

 string[] strUserInitials = System.Web.HttpContext.Current.Request.ServerVariables["LOGON_USER"].Split('\\')); 
+17
source

put using System.Web; and using System; to the source file ...

+3
source

You can try this:

 System.Web.HttpContext 
0
source

All Articles