T
tshad
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.HttpCookie' 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.WebControls;
using System.Web.SessionState;
using System.Data;
using System.Data.SqlClient;
using System.Web.HttpCookie;
using System.Web.HttpCookieCollection;
using System.Web.HttpResponse;
using System.Web.HttpRequest;
using System.Web.HttpContext;
using System.Web.HttpApplication;
using System.Web.HttpApplicationState;
using System.Collections;
using Microsoft.VisualBasic;
namespace MyFunctions
{
public class PageInit
{
public static void PageSetup(MyFunctions.Page thePage)
{
string url;
string stemp;
string urlNoParams;
Label UserLoggedOn = (Label)thePage.FindControl("UserLoggedOn");
Label UserLoggedOnLabel =
(Label)thePage.FindControl("UserLoggedOnLabel");
if ((UserLoggedOn != null)) {
if (HttpContext.Current.session("LoggedIn") != null) {
if (HttpContext.Current.session("firstName") != null) {
UserLoggedOn.Text = UserLoggedOn.Text +
HttpContext.Current.session("firstName");
if (HttpContext.Current.session("lastName") != null)
{
UserLoggedOn.Text = UserLoggedOn.Text + " " +
HttpContext.Current.session("lastName");
}
}
if ((UserLoggedOn != null)) {
UserLoggedOn.visible = true;
if ((UserLoggedOnLabel != null))
UserLoggedOnLabel.visible = true;
}
}
}
if ((!thePage.IsRefresh)) {
if (((HttpContext.Current.session("User") != null)))
HttpContext.Current.session("LastPageVisited") =
HttpContext.Current.Session("User").LastPageVisited;
url =
HttpContext.Current.Request.Url.ToString.Substring(HttpContext.Current.Request.Url.ToString.LastIndexOf("/")
+ 1);
urlNoParams = url;
if (url.LastIndexOf("?") > -1)
urlNoParams = Url.Substring(0, url.LastIndexOf("?"));
if (((HttpContext.Current.session("User") != null)))
HttpContext.Current.Session("User").LastPageVisited =
urlNoParams;
url = "";
urlNoParams = "";
if ((HttpContext.Current.Request.UrlReferrer != null)) {
url =
HttpContext.Current.Request.UrlReferrer.ToString.Substring(HttpContext.Current.Request.UrlReferrer.ToString.LastIndexOf("/")
+ 1);
if (url.LastIndexOf("?") > -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.Current.session("stemp") =
HttpContext.Current.Request.Url.ToString.IndexOf("/employer/");
if
(HttpContext.Current.Request.Url.ToString.IndexOf("disabledAccount.aspx")
== -1) {
if
(HttpContext.Current.Request.Url.ToString.IndexOf("/employer/") > -1) {
if ((HttpContext.Current.session("CompanyDisabled") !=
null)) {
HttpContext.Current.Response.Redirect("disabledAccount.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.WebControls
Imports System.Web.SessionState
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.HttpCookie
Imports System.Web.HttpCookieCollection
Imports System.Web.HttpResponse
Imports System.Web.HttpRequest
imports System.Web.HttpContext
Imports System.Web.HttpApplication
Imports System.Web.HttpApplicationState
Imports System.Collections
Imports Microsoft.VisualBasic
***************************************************
Where Imports is the same as Using. So why am I getting the error?
The errors are from HTTPCookie to HttpApplicationState.
My compiler line for c# that doesn't work is:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc /t:library PageInit.cs
/r:system.web.dll /r:system.data.dll /r:system.dll
/r:Microsoft.VisualBasic.dll /r:refresh.dll
And the compiler line for vb.net that does work is:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\vbc /t:library PageInit.vb
/r:system.web.dll /r:system.data.dll /r:system.dll
/r:Microsoft.VisualBasic.dll /r:refresh.dll
As you can see virtually identical.
Thanks,
Tom
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.HttpCookie' 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.WebControls;
using System.Web.SessionState;
using System.Data;
using System.Data.SqlClient;
using System.Web.HttpCookie;
using System.Web.HttpCookieCollection;
using System.Web.HttpResponse;
using System.Web.HttpRequest;
using System.Web.HttpContext;
using System.Web.HttpApplication;
using System.Web.HttpApplicationState;
using System.Collections;
using Microsoft.VisualBasic;
namespace MyFunctions
{
public class PageInit
{
public static void PageSetup(MyFunctions.Page thePage)
{
string url;
string stemp;
string urlNoParams;
Label UserLoggedOn = (Label)thePage.FindControl("UserLoggedOn");
Label UserLoggedOnLabel =
(Label)thePage.FindControl("UserLoggedOnLabel");
if ((UserLoggedOn != null)) {
if (HttpContext.Current.session("LoggedIn") != null) {
if (HttpContext.Current.session("firstName") != null) {
UserLoggedOn.Text = UserLoggedOn.Text +
HttpContext.Current.session("firstName");
if (HttpContext.Current.session("lastName") != null)
{
UserLoggedOn.Text = UserLoggedOn.Text + " " +
HttpContext.Current.session("lastName");
}
}
if ((UserLoggedOn != null)) {
UserLoggedOn.visible = true;
if ((UserLoggedOnLabel != null))
UserLoggedOnLabel.visible = true;
}
}
}
if ((!thePage.IsRefresh)) {
if (((HttpContext.Current.session("User") != null)))
HttpContext.Current.session("LastPageVisited") =
HttpContext.Current.Session("User").LastPageVisited;
url =
HttpContext.Current.Request.Url.ToString.Substring(HttpContext.Current.Request.Url.ToString.LastIndexOf("/")
+ 1);
urlNoParams = url;
if (url.LastIndexOf("?") > -1)
urlNoParams = Url.Substring(0, url.LastIndexOf("?"));
if (((HttpContext.Current.session("User") != null)))
HttpContext.Current.Session("User").LastPageVisited =
urlNoParams;
url = "";
urlNoParams = "";
if ((HttpContext.Current.Request.UrlReferrer != null)) {
url =
HttpContext.Current.Request.UrlReferrer.ToString.Substring(HttpContext.Current.Request.UrlReferrer.ToString.LastIndexOf("/")
+ 1);
if (url.LastIndexOf("?") > -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.Current.session("stemp") =
HttpContext.Current.Request.Url.ToString.IndexOf("/employer/");
if
(HttpContext.Current.Request.Url.ToString.IndexOf("disabledAccount.aspx")
== -1) {
if
(HttpContext.Current.Request.Url.ToString.IndexOf("/employer/") > -1) {
if ((HttpContext.Current.session("CompanyDisabled") !=
null)) {
HttpContext.Current.Response.Redirect("disabledAccount.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.WebControls
Imports System.Web.SessionState
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.HttpCookie
Imports System.Web.HttpCookieCollection
Imports System.Web.HttpResponse
Imports System.Web.HttpRequest
imports System.Web.HttpContext
Imports System.Web.HttpApplication
Imports System.Web.HttpApplicationState
Imports System.Collections
Imports Microsoft.VisualBasic
***************************************************
Where Imports is the same as Using. So why am I getting the error?
The errors are from HTTPCookie to HttpApplicationState.
My compiler line for c# that doesn't work is:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc /t:library PageInit.cs
/r:system.web.dll /r:system.data.dll /r:system.dll
/r:Microsoft.VisualBasic.dll /r:refresh.dll
And the compiler line for vb.net that does work is:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\vbc /t:library PageInit.vb
/r:system.web.dll /r:system.data.dll /r:system.dll
/r:Microsoft.VisualBasic.dll /r:refresh.dll
As you can see virtually identical.
Thanks,
Tom