Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

The problem line is:

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

Anyone know why this is happening?

I am working on a webservice (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;
like image 618
oshirowanen Avatar asked Aug 04 '11 11:08

oshirowanen


3 Answers

You have to reference to System.Web and import the namespace System.Web:

using System.Web;

I would not use Convert at all:

string[] strUserInitials = System.Web.HttpContext.Current.Request.ServerVariables["LOGON_USER"].Split('\\'));
like image 175
slfan Avatar answered Nov 10 '22 08:11

slfan


You need [] instead of ():

string[] strUserInitials = System.Web.HttpContext.Current.Request.ServerVariables["LOGON_USER"].Split(System.Convert.ToChar(@"\"));
like image 28
alun Avatar answered Nov 10 '22 09:11

alun


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

like image 3
Yahia Avatar answered Nov 10 '22 08:11

Yahia