I have a file that I converted from VB.Net to C# that works fine in VB.Net
when I compile but not in C# using the same libraries.
The error I am getting is:
PageInit.cs(9,7 ): error CS0138: A using namespace directive can only be
applied
to namespaces; 'System.Web.Htt pCookie' is a class not a namespace
The code is:
*************** *************** ****
using System;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.Sess ionState;
using System.Data;
using System.Data.Sql Client;
using System.Web.Http Cookie;
using System.Web.Http CookieCollectio n;
using System.Web.Http Response;
using System.Web.Http Request;
using System.Web.Http Context;
using System.Web.Http Application;
using System.Web.Http ApplicationStat e;
using System.Collecti ons;
using Microsoft.Visua lBasic;
namespace MyFunctions
{
public class PageInit
{
public static void PageSetup(MyFun ctions.Page thePage)
{
string url;
string stemp;
string urlNoParams;
Label UserLoggedOn = (Label)thePage. FindControl("Us erLoggedOn");
Label UserLoggedOnLab el =
(Label)thePage. FindControl("Us erLoggedOnLabel ");
if ((UserLoggedOn != null)) {
if (HttpContext.Cu rrent.session(" LoggedIn") != null) {
if (HttpContext.Cu rrent.session(" firstName") != null) {
UserLoggedOn.Te xt = UserLoggedOn.Te xt +
HttpContext.Cur rent.session("f irstName");
if (HttpContext.Cu rrent.session(" lastName") != null)
{
UserLoggedOn.Te xt = UserLoggedOn.Te xt + " " +
HttpContext.Cur rent.session("l astName");
}
}
if ((UserLoggedOn != null)) {
UserLoggedOn.vi sible = true;
if ((UserLoggedOnL abel != null))
UserLoggedOnLab el.visible = true;
}
}
}
if ((!thePage.IsRe fresh)) {
if (((HttpContext. Current.session ("User") != null)))
HttpContext.Cur rent.session("L astPageVisited" ) =
HttpContext.Cur rent.Session("U ser").LastPageV isited;
url =
HttpContext.Cur rent.Request.Ur l.ToString.Subs tring(HttpConte xt.Current.Requ est.Url.ToStrin g.LastIndexOf("/")
+ 1);
urlNoParams = url;
if (url.LastIndexO f("?") -1)
urlNoParams = Url.Substring(0 , url.LastIndexOf ("?"));
if (((HttpContext. Current.session ("User") != null)))
HttpContext.Cur rent.Session("U ser").LastPageV isited =
urlNoParams;
url = "";
urlNoParams = "";
if ((HttpContext.C urrent.Request. UrlReferrer != null)) {
url =
HttpContext.Cur rent.Request.Ur lReferrer.ToStr ing.Substring(H ttpContext.Curr ent.Request.Url Referrer.ToStri ng.LastIndexOf( "/")
+ 1);
if (url.LastIndexO f("?") -1) {
urlNoParams = Url.Substring(0 ,
url.LastIndexOf ("?"));
}
}
}
// Check to see if we are already at disabledAccount - if yes
don't test for /employer/ - we are already there
// if no - then check if we are a company account (/employer/)
if so & Company disabled - send to disabledAccount .aspx
HttpContext.Cur rent.session("s temp") =
HttpContext.Cur rent.Request.Ur l.ToString.Inde xOf("/employer/");
if
(HttpContext.Cu rrent.Request.U rl.ToString.Ind exOf("disabledA ccount.aspx")
== -1) {
if
(HttpContext.Cu rrent.Request.U rl.ToString.Ind exOf("/employer/") -1) {
if ((HttpContext.C urrent.session( "CompanyDisable d") !=
null)) {
HttpContext.Cur rent.Response.R edirect("disabl edAccount.aspx" );
}
}
}
}
}
}
*************** *************** ******
In the VB.Net code it is:
*************** *************** *************8
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.Sess ionState
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web.Http Cookie
Imports System.Web.Http CookieCollectio n
Imports System.Web.Http Response
Imports System.Web.Http Request
imports System.Web.Http Context
Imports System.Web.Http Application
Imports System.Web.Http ApplicationStat e
Imports System.Collecti ons
Imports Microsoft.Visua lBasic
*************** *************** *************** ******
Where Imports is the same as Using. So why am I getting the error?
The errors are from HTTPCookie to HttpApplication State.
My compiler line for c# that doesn't work is:
C:\WINDOWS\Micr osoft.NET\Frame work\v1.1.4322\ csc /t:library PageInit.cs
/r:system.web.dl l /r:system.data.d ll /r:system.dll
/r:Microsoft.Vis ualBasic.dll /r:refresh.dll
And the compiler line for vb.net that does work is:
C:\WINDOWS\Micr osoft.NET\Frame work\v1.1.4322\ vbc /t:library PageInit.vb
/r:system.web.dl l /r:system.data.d ll /r:system.dll
/r:Microsoft.Vis ualBasic.dll /r:refresh.dll
As you can see virtually identical.
Thanks,
Tom