Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

HttpContext in c# class

  Asked By: Jose    Date: Aug 14    Category: Asp.net    Views: 5325
  

this line of code working great in vb class but not with c#

why?

dim sn as string = HttpContext.Current.Request.ServerVariables("SCRIPT_NAME")

Share: 

 

10 Answers Found

 
Answer #1    Answered By: Josie Roberts     Answered On: Aug 14

Something like this might work:

String sn = HttpContext.Current.Request.ServerVariables("SCRIPT_NAME");

I'm not a C# expert, though.

 
Answer #2    Answered By: Marc Anderson     Answered On: Aug 14

i tried.
not working.
it has problems with the HttpContext.

 
Answer #3    Answered By: Kiet Jainukul     Answered On: Aug 14

string s = HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]; //
notice the [] and not ()


If still having problems, send the exact error message.

 
Answer #4    Answered By: Mae Roberts     Answered On: Aug 14

Have you got a using System.Web; statement at the top of your class, and a
reference to the System.Web.dll file in your compiler command?

 
Answer #5    Answered By: Freda Lane     Answered On: Aug 14

i tried and im getting:
Y:\demo\moreshetObjects\modulObject.cs(29): The type or namespace name
'HttpContext' could not be found (are you missing a using directive or an
assembly reference?)
string s = HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]; //

 
Answer #6    Answered By: Hooriya Khan     Answered On: Aug 14

Make sure you have this at the top:

using System.Web;

 
Answer #7    Answered By: Adalia Fischer     Answered On: Aug 14

i tried...

Y:\demo\moreshetObjects\userObject.cs(10): The type or namespace name 'Web' does
not exist in the class  or namespace 'System' (are you missing an assembly
reference?)

 
Answer #8    Answered By: Tracy Myers     Answered On: Aug 14

codebehind or all in one aspx ??

if all in one aspx, put this at the top:

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>

 
Answer #9    Answered By: Vonda Ramirez     Answered On: Aug 14

it is not codeBehind or all aspx

just some class

 
Answer #10    Answered By: Bach-yen Nguyen     Answered On: Aug 14

reference to the System.Web.dll was the problem.
i didnt do that.

 
Didn't find what you were looking for? Find more on HttpContext in c# class Or get search suggestion and latest updates.




Tagged: