473,216 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

equivalent C# for VB.NET "Session"

Hi groups,

Can anyone give me the equivalent C# sharp code for this VB.ET code,

:: VB.NET ::

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles MyBase.Load
'This event routine in the loginCheck user control fires when the
protected
'page loads. If the user hasn't logged in, loginCheck redirects the
user to
'the page specified by LoginPageURL for validation. If the user has
logged in,
'he or she gets access to the protected page.

If Not Enabled Then Exit Sub
If IsNothing(Session("LoginType")) Then Exit Sub
If CType(Session("LoginType"), _
String).Length > 0 Then
If IsNothing(Session(LoginPageURL & _
"_Valid")) Then
Session("LoginTarget") = _
Request.ServerVariables _
("Script_Name")
Response.Redirect(LoginPageURL)
Else
If CType(Session(LoginPageURL & _
"_Valid"), String).Length = 0 Then
Session("LoginTarget") = _
Request.ServerVariables _
("Script_Name")
Response.Redirect(LoginPageURL)
End If
End If
End If
End Sub

C#?

I used an auto tool to do this and got:

The MS VS 2003 always complains "Session" as below:

c:\inetpub\wwwroot\passwordProtectCSharp\Global.as ax.cs(42):
'System.Web.HttpApplication.Session' denotes a 'property' where a 'method'
was expected

Anyone has any suggestions?

Thanks. -Dale
Nov 17 '05 #1
14 5870
<"=?Utf-8?B?ZGFsZSB6aGFuZw==?=" <dale
zh***@discussions.microsoft.com>> wrote:

<snip>
I used an auto tool to do this and got:

The MS VS 2003 always complains "Session" as below:

c:\inetpub\wwwroot\passwordProtectCSharp\Global.as ax.cs(42):
'System.Web.HttpApplication.Session' denotes a 'property' where a 'method'
was expected

Anyone has any suggestions?


That suggests that you're using it as:

Session("LoginType") when you should be using Session["LoginType"] -
i.e. you should be using the indexer of the Session property.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
Thanks, Jon. That problem was sloved.

But a few new ones:
1. VB:: Response.Redirect _
(Session("LoginTarget"))

C#::?
Response.Redirect(Session["LoginTarget"]);
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(84): The best
overloaded method match for 'System.Web.HttpResponse.Redirect(string)' has
some invalid arguments
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(84): Argument
'1': cannot convert from 'object' to 'string'

2.VB:: Dim sPage As String = Session("LoginTarget")
C#:: string sPage = Session["LoginTarget"];
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(108): Cannot
implicitly convert type 'object' to 'string'

3.VB::
Private Function CheckPass(ByVal User As String, ByVal Password As
String) As Boolean
Dim dbConn As OleDbConnection
Dim dbCmd As OleDbCommand
Dim dbDR As OleDbDataReader
Dim sConn As String = Connect()
Dim sSQL As String
CheckPass = False
C#::
private bool CheckPass(string User, string Password)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string sConn = Connect();
string sSQL;
CheckPass = false; ???
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(131): Method
'passwordProtectCSharp.loginControl.CheckPass(stri ng, string)' referenced
without parentheses

4. VB:: Date.Now.ToString
c#??

5. VB:: If (datData.ToString).Length Then
C#:: if (datData.ToString.Length)
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(272):
'System.DateTime.ToString(string)' denotes a 'method' which is not valid in
the given context

Many thanks. -Dale
"Jon Skeet [C# MVP]" wrote:
<"=?Utf-8?B?ZGFsZSB6aGFuZw==?=" <dale
zh***@discussions.microsoft.com>> wrote:

<snip>
I used an auto tool to do this and got:

The MS VS 2003 always complains "Session" as below:

c:\inetpub\wwwroot\passwordProtectCSharp\Global.as ax.cs(42):
'System.Web.HttpApplication.Session' denotes a 'property' where a 'method'
was expected

Anyone has any suggestions?


That suggests that you're using it as:

Session("LoginType") when you should be using Session["LoginType"] -
i.e. you should be using the indexer of the Session property.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #3
dale zhang <da*******@discussions.microsoft.com> wrote:
Thanks, Jon. That problem was sloved.

But a few new ones:
1. VB:: Response.Redirect _
(Session("LoginTarget"))

C#::?
Response.Redirect(Session["LoginTarget"]);
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(84): The best
overloaded method match for 'System.Web.HttpResponse.Redirect(string)' has
some invalid arguments
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(84): Argument
'1': cannot convert from 'object' to 'string'
You'll need to cast to string:

Response.Redirect ((string) Session["LoginTarget"]);

The fact that you didn't in VB suggests that you had Option Strict
turned off - a bad idea!
2.VB:: Dim sPage As String = Session("LoginTarget")
C#:: string sPage = Session["LoginTarget"];
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(108): Cannot
implicitly convert type 'object' to 'string'
Same again.
3.VB::
Private Function CheckPass(ByVal User As String, ByVal Password As
String) As Boolean
Dim dbConn As OleDbConnection
Dim dbCmd As OleDbCommand
Dim dbDR As OleDbDataReader
Dim sConn As String = Connect()
Dim sSQL As String
CheckPass = False
C#::
private bool CheckPass(string User, string Password)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string sConn = Connect();
string sSQL;
CheckPass = false; ???
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(131): Method
'passwordProtectCSharp.loginControl.CheckPass(stri ng, string)' referenced
without parentheses
Not sure on that - what is "CheckPass = false" meant to do, exactly? Is
there a variable called CheckPass somewhere? Don't forget that C# is
case-sensitive, whereas VB.NET isn't.
4. VB:: Date.Now.ToString
c#??
DateTime.Now.ToString()
5. VB:: If (datData.ToString).Length Then
C#:: if (datData.ToString.Length)
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(272):
'System.DateTime.ToString(string)' denotes a 'method' which is not valid in
the given context


Use ToString().Length rather than ToString.Length. VB.NET doesn't make
you use brackets when there aren't any parameters, unfortunately -
making method calls look like properties :(

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
Jon,

Your answers are very helpful. We are close to success. A few more stand as
below:
1: VB::
Private Function Connect() As String
Dim sConnect As String
'this value could go directly in the Global.asax.vb declarations
Select Case CType(Application("DBType"), String).ToLower
Case "sqlserver"
sConnect =
ConfigurationSettings.AppSettings.Get("SQLConnecti on")
'Return "Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;Initial
Catalog=PasswordProtect;Data Source=(local)"
Case "access"
sConnect =
ConfigurationSettings.AppSettings.Get("AccessConne ction")
'Return "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\DBs\PasswordProtect.mdb;Persist Security Info=False"
End Select
Return sConnect
End Function

C#::
private string Connect()
{
string sConnect;
// this value could go directly in the Global.asax.vb declarations
switch (((string)(Application["DBType"])).ToLower())
{
case "sqlserver":
sConnect = ConfigurationSettings.AppSettings.Get("SQLConnecti on");
// Return "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;Initial Catalog=PasswordProtect;Data Source=(local)"
break;
case "access":
sConnect = ConfigurationSettings.AppSettings.Get("AccessConne ction");
// Return "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\DBs\PasswordProtect.mdb;Persist Security Info=False"
break;
}
return sConnect;
}
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(229): Use of
unassigned local variable 'sConnect'

It in fact complains about switch input. I mean it can not switch and assign
value. Can not switch happened later as well.

2. VB:: If (datData.ToString).Length Then
C#:: if (datData.ToString().Length)

c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(264): Cannot
implicitly convert type 'int' to 'bool'

3. VB:: sArray = WebPath.Split("/")
C#:: sArray = WebPath.Split("/");
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(294): The best
overloaded method match for 'string.Split(params char[])' has some invalid
arguments
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(294): Argument
'1': cannot convert from 'string' to 'char[]'

Thanks. -Dale

"Jon Skeet [C# MVP]" wrote:
dale zhang <da*******@discussions.microsoft.com> wrote:
Thanks, Jon. That problem was sloved.

But a few new ones:
1. VB:: Response.Redirect _
(Session("LoginTarget"))

C#::?
Response.Redirect(Session["LoginTarget"]);
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(84): The best
overloaded method match for 'System.Web.HttpResponse.Redirect(string)' has
some invalid arguments
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(84): Argument
'1': cannot convert from 'object' to 'string'


You'll need to cast to string:

Response.Redirect ((string) Session["LoginTarget"]);

The fact that you didn't in VB suggests that you had Option Strict
turned off - a bad idea!
2.VB:: Dim sPage As String = Session("LoginTarget")
C#:: string sPage = Session["LoginTarget"];
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(108): Cannot
implicitly convert type 'object' to 'string'


Same again.
3.VB::
Private Function CheckPass(ByVal User As String, ByVal Password As
String) As Boolean
Dim dbConn As OleDbConnection
Dim dbCmd As OleDbCommand
Dim dbDR As OleDbDataReader
Dim sConn As String = Connect()
Dim sSQL As String
CheckPass = False
C#::
private bool CheckPass(string User, string Password)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string sConn = Connect();
string sSQL;
CheckPass = false; ???
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(131): Method
'passwordProtectCSharp.loginControl.CheckPass(stri ng, string)' referenced
without parentheses


Not sure on that - what is "CheckPass = false" meant to do, exactly? Is
there a variable called CheckPass somewhere? Don't forget that C# is
case-sensitive, whereas VB.NET isn't.
4. VB:: Date.Now.ToString
c#??


DateTime.Now.ToString()
5. VB:: If (datData.ToString).Length Then
C#:: if (datData.ToString.Length)
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(272):
'System.DateTime.ToString(string)' denotes a 'method' which is not valid in
the given context


Use ToString().Length rather than ToString.Length. VB.NET doesn't make
you use brackets when there aren't any parameters, unfortunately -
making method calls look like properties :(

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #5
dale zhang <da*******@discussions.microsoft.com> wrote:
C#::
private string Connect()
{
string sConnect;
// this value could go directly in the Global.asax.vb declarations
switch (((string)(Application["DBType"])).ToLower())
{
case "sqlserver":
sConnect = ConfigurationSettings.AppSettings.Get("SQLConnecti on");
// Return "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;Initial Catalog=PasswordProtect;Data Source=(local)"
break;
case "access":
sConnect = ConfigurationSettings.AppSettings.Get("AccessConne ction");
// Return "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\DBs\PasswordProtect.mdb;Persist Security Info=False"
break;
}
return sConnect;
}
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(229): Use of
unassigned local variable 'sConnect'

It in fact complains about switch input. I mean it can not switch and assign
value. Can not switch happened later as well.
The problem is that if the DBType is neither "access" nor "sqlserver",
what are you expecting it to return?

Either set a "default" case, or assign a value to sConnect to start
with.
2. VB:: If (datData.ToString).Length Then
C#:: if (datData.ToString().Length)

c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(264): Cannot
implicitly convert type 'int' to 'bool'
Change it to:

if (datData.ToString().Length > 0)
3. VB:: sArray = WebPath.Split("/")
C#:: sArray = WebPath.Split("/");
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(294): The best
overloaded method match for 'string.Split(params char[])' has some invalid
arguments
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(294): Argument
'1': cannot convert from 'string' to 'char[]'


Change it to WebPath.Split('/')

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
I think you ar right: the DBType is neither "access" nor "sqlserver". I could
not understand how this happens.

it is defined in Global.asax.vb as
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
'Choices: "SQLServer","Access"
Application("DBType") = "Access"
End Sub

C#::
void Application_BeginRequest(object sender, EventArgs e)
{
// Choices: "SQLServer","Access"
Application["DBType"] = "Access";
}

I am using it in loginControl.ascx.cs as
private string Connect()
{
string sConnect;
// this value could go directly in the Global.asax.vb declarations
switch (((string)(Application["DBType"])).ToLower())
{
case "sqlserver":

How come the global variable can not be passed in?

Thank you. I hope this is the last one. -Dale

"Jon Skeet [C# MVP]" wrote:
dale zhang <da*******@discussions.microsoft.com> wrote:
C#::
private string Connect()
{
string sConnect;
// this value could go directly in the Global.asax.vb declarations
switch (((string)(Application["DBType"])).ToLower())
{
case "sqlserver":
sConnect = ConfigurationSettings.AppSettings.Get("SQLConnecti on");
// Return "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;Initial Catalog=PasswordProtect;Data Source=(local)"
break;
case "access":
sConnect = ConfigurationSettings.AppSettings.Get("AccessConne ction");
// Return "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\DBs\PasswordProtect.mdb;Persist Security Info=False"
break;
}
return sConnect;
}
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(229): Use of
unassigned local variable 'sConnect'

It in fact complains about switch input. I mean it can not switch and assign
value. Can not switch happened later as well.


The problem is that if the DBType is neither "access" nor "sqlserver",
what are you expecting it to return?

Either set a "default" case, or assign a value to sConnect to start
with.
2. VB:: If (datData.ToString).Length Then
C#:: if (datData.ToString().Length)

c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(264): Cannot
implicitly convert type 'int' to 'bool'


Change it to:

if (datData.ToString().Length > 0)
3. VB:: sArray = WebPath.Split("/")
C#:: sArray = WebPath.Split("/");
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(294): The best
overloaded method match for 'string.Split(params char[])' has some invalid
arguments
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(294): Argument
'1': cannot convert from 'string' to 'char[]'


Change it to WebPath.Split('/')

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #7
seems my post is not on. here is the 2nd try.

you are right: Application("DBType") did not pass. it is defined in
global.asax.vb as below:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
'Choices: "SQLServer","Access"
Application("DBType") = "Access"
End Sub
C#::
void Application_BeginRequest(object sender, EventArgs e)
{
// Choices: "SQLServer","Access"
Application["DBType"] = "Access";
}
I am using it in loginControl.ascx.cs as previous post. why not pass?

hope this is last one. thanks a lot. -dale

"Jon Skeet [C# MVP]" wrote:
dale zhang <da*******@discussions.microsoft.com> wrote:
C#::
private string Connect()
{
string sConnect;
// this value could go directly in the Global.asax.vb declarations
switch (((string)(Application["DBType"])).ToLower())
{
case "sqlserver":
sConnect = ConfigurationSettings.AppSettings.Get("SQLConnecti on");
// Return "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;Initial Catalog=PasswordProtect;Data Source=(local)"
break;
case "access":
sConnect = ConfigurationSettings.AppSettings.Get("AccessConne ction");
// Return "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\DBs\PasswordProtect.mdb;Persist Security Info=False"
break;
}
return sConnect;
}
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(229): Use of
unassigned local variable 'sConnect'

It in fact complains about switch input. I mean it can not switch and assign
value. Can not switch happened later as well.


The problem is that if the DBType is neither "access" nor "sqlserver",
what are you expecting it to return?

Either set a "default" case, or assign a value to sConnect to start
with.
2. VB:: If (datData.ToString).Length Then
C#:: if (datData.ToString().Length)

c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(264): Cannot
implicitly convert type 'int' to 'bool'


Change it to:

if (datData.ToString().Length > 0)
3. VB:: sArray = WebPath.Split("/")
C#:: sArray = WebPath.Split("/");
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(294): The best
overloaded method match for 'string.Split(params char[])' has some invalid
arguments
c:\inetpub\wwwroot\passwordProtectCSharp\loginCont rol.ascx.cs(294): Argument
'1': cannot convert from 'string' to 'char[]'


Change it to WebPath.Split('/')

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #8
dale zhang <da*******@discussions.microsoft.com> wrote:
seems my post is not on. here is the 2nd try.

you are right: Application("DBType") did not pass. it is defined in
global.asax.vb as below:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
'Choices: "SQLServer","Access"
Application("DBType") = "Access"
End Sub
C#::
void Application_BeginRequest(object sender, EventArgs e)
{
// Choices: "SQLServer","Access"
Application["DBType"] = "Access";
}
I am using it in loginControl.ascx.cs as previous post. why not pass?

hope this is last one. thanks a lot. -dale


Sorry, I don't understand your question. What do you mean by "why not
pass?"?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #9
I am wondering why global application state variable Application("DBType")
can not be accessed by all files. I think I can figure this out later. I hard
code the option for now.

The C# code can run. But I have a default page which has a hyperlink to a
private page. The private page has login check. Somehow, the Page_Init and
Page_Load in the private page do not get executed (do not break). Hence I can
not do login check. Is this caused by CodeBehind (=privatePage)?

Thanks. -dale
"Jon Skeet [C# MVP]" wrote:
dale zhang <da*******@discussions.microsoft.com> wrote:
seems my post is not on. here is the 2nd try.

you are right: Application("DBType") did not pass. it is defined in
global.asax.vb as below:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
'Choices: "SQLServer","Access"
Application("DBType") = "Access"
End Sub
C#::
void Application_BeginRequest(object sender, EventArgs e)
{
// Choices: "SQLServer","Access"
Application["DBType"] = "Access";
}
I am using it in loginControl.ascx.cs as previous post. why not pass?

hope this is last one. thanks a lot. -dale


Sorry, I don't understand your question. What do you mean by "why not
pass?"?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #10
dale zhang <da*******@discussions.microsoft.com> wrote:
I am wondering why global application state variable Application("DBType")
can not be accessed by all files. I think I can figure this out later. I hard
code the option for now.
It's not a variable - it's a property of the Page instance, so unless
you have a reference to the page, you won't be able to get at it.
The C# code can run. But I have a default page which has a hyperlink to a
private page. The private page has login check. Somehow, the Page_Init and
Page_Load in the private page do not get executed (do not break). Hence I can
not do login check. Is this caused by CodeBehind (=privatePage)?


Wouldn't like to say, I'm afraid - I suggest you ask in the ASP.NET
newsgroup, with a complete example.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #11
I looked at the ASP.NET newsgroup here, I could not find a way to attach
files to the message board. Any idea? Thanks. -Dale

"Jon Skeet [C# MVP]" wrote:
dale zhang <da*******@discussions.microsoft.com> wrote:
I am wondering why global application state variable Application("DBType")
can not be accessed by all files. I think I can figure this out later. I hard
code the option for now.


It's not a variable - it's a property of the Page instance, so unless
you have a reference to the page, you won't be able to get at it.
The C# code can run. But I have a default page which has a hyperlink to a
private page. The private page has login check. Somehow, the Page_Init and
Page_Load in the private page do not get executed (do not break). Hence I can
not do login check. Is this caused by CodeBehind (=privatePage)?


Wouldn't like to say, I'm afraid - I suggest you ask in the ASP.NET
newsgroup, with a complete example.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #12
what is the reason for a private page?

if the page shows in a browser, it would have fired four page events - init,
pre-render, unload (scratching my head for the other one). The debugger
breaking into the page has nothing to do with the page event firing.

one thing you can do is to break before you call the * private page. Then
you can step into the call to see what is going.

unless you have some funky logic or design requirement, you should implement
the login page as an ordinary aspx page. I doubt that is the reason for your
problem though, but i thought i would mention it.
--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
-------------------------------------------------------------------------------
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
dale zhang <da*******@discussions.microsoft.com> wrote:
I am wondering why global application state variable
Application("DBType")
can not be accessed by all files. I think I can figure this out later. I
hard
code the option for now.


It's not a variable - it's a property of the Page instance, so unless
you have a reference to the page, you won't be able to get at it.
The C# code can run. But I have a default page which has a hyperlink to a
private page. The private page has login check. Somehow, the Page_Init
and
Page_Load in the private page do not get executed (do not break). Hence I
can
not do login check. Is this caused by CodeBehind (=privatePage)?


Wouldn't like to say, I'm afraid - I suggest you ask in the ASP.NET
newsgroup, with a complete example.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #13
dale zhang <da*******@discussions.microsoft.com> wrote:
I looked at the ASP.NET newsgroup here, I could not find a way to attach
files to the message board. Any idea? Thanks. -Dale


Yes - use a "proper" newsreader and connect to msnews.microsoft.com and
post a message that way, rather than using the web interface. I'm sure
there's a way of posting via the web interface, but I don't use it
myself, far preferring a tool designed specifically for newsgroups. You
can use Outlook Express if you want, although there are many other
newsreaders available too.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #14
Thank you all for your helps. Especially from Jon.

My C# one is fully functional. All wired things have been fixed. The main
reasons of the problem are:

1. auto converter is not right all the time.
2. the VB project was from VS.NET 1.0. Too old. we need to update those
related like Page_Init() in VS 2003.

-Dale

"Jon Skeet [C# MVP]" wrote:
<"=?Utf-8?B?ZGFsZSB6aGFuZw==?=" <dale
zh***@discussions.microsoft.com>> wrote:

<snip>
I used an auto tool to do this and got:

The MS VS 2003 always complains "Session" as below:

c:\inetpub\wwwroot\passwordProtectCSharp\Global.as ax.cs(42):
'System.Web.HttpApplication.Session' denotes a 'property' where a 'method'
was expected

Anyone has any suggestions?


That suggests that you're using it as:

Session("LoginType") when you should be using Session["LoginType"] -
i.e. you should be using the indexer of the Session property.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: TWACS | last post by:
How do I add and get session defined variables? when I do this Session("USERID") = "NAME"; I get System.Web.UI.Page.Session' denotes a 'property' where a 'method' was expected Thanks,
9
by: bajopalabra | last post by:
hi session("myVar") = rs.getRows( ) don't work when number of records is greater than 10 does anybody know WHY ??? is it a Session object limitation ??? thanks
1
by: Andreas Klemt | last post by:
Hello, let's say my session("myDataTable") is type of DataTable Now what is faster? a) Dim dv As New DataView(session("myDataTable")) b) Dim dv As New DataView(CType(session("myDataTable"),...
3
by: Jeff Smythe | last post by:
I simply want to execute some code once when a new session of my ASP.NET application is started (I'm not using session state for anything else - just writing some data to a database). I thought...
13
by: dee | last post by:
Hi My code complies the following line: Session("passed") = 1 but puts wiggly error line under the second Session("passed") in the following expression: Session("passed") = Session("passed") +...
10
by: thomson | last post by:
Hi, i create a session variable in C# as follows Session , but iam not able to access the variable in VB.net like intmode=Session("var"); Why is that ? Regards
4
by: R.A.M. | last post by:
Hello, I am writing ASP.NET application in which I need to use User Profiles and Session mechanisms. Here I include part of my source code (Admin.cs): using System; using System.Data; using...
10
by: Kurda Yon | last post by:
Hi, I set the register_globals off and try to get my code working under the new conditions. I stuck on the following problem: Warning: Unknown(): Your script possibly relies on a session side-...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.