ASP.NET "Get path strPath = Session("Path").ToString()"

G

Guest

Hi all

I am having problem in ASP.NET and I hope I can find solution in here

While studying the "MCAD/MCSD Training Kit—Developing Web Applications with Microsoft Visual Basic .NET and Microsoft Visual C# .NET" Training kit I get an error. Here is the error

--------------------------------------------------------------------------------------------------------------------------------------------
Error: Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object

Source Error:
Line 36:
Line 37: ' Get path
Line 38: strPath = Session("C:\Inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c").ToString(
Line 39: ' If this is not a post-back event
Line 40: If Not IsPostBack The


Source File: c:\inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c\FileManager.aspx.vb Line: 38

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.
Chapter_04c.FileManager.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c\FileManager.aspx.vb:3
System.Web.UI.Control.OnLoad(EventArgs e) +6
System.Web.UI.Control.LoadRecursive() +3
System.Web.UI.Page.ProcessRequestMain() +73

---------------------------------------------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
-------------------------------------------------------------------------------------------------------------------------------------------


I also have this information in my hand:-
--------------------------------------------
IMPORTANT
To create and delete files, the ASPNET user account must have write and modify privileges in the application’s root folder. By default, the ASPNET user account has only read and execute privileges. See Chapter 9, “Building and Deploying Web Applications,†for information about how to assign security privileges in the application folder
---------------------------------------------

Currently I am accesing with VS Studion.Net account so ASPNET account is not a problem

My problem is how to get the path in ASP.NET. And this is not a PostBack event

Line 37: ' Get path
Line 38: strPath = Session("C:\Inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c").ToString(
Line 39: ' If this is not a post-back event
Line 40: If Not IsPostBack The

Can anyone tell me where I can find information to correct the problem. But I am more than happy to write the correct code that if anyone knows the answer

I thank you in advance

Rgds
GC
 
M

Marina

This is because a session variable with that name hasn't been created, so
session("...") gets evaluated to Nothing. When you call .ToString() on
Nothing, you get a NullReferenceException. You need to make sure that
session variable is there before you try to do anything with it.

GC said:
Hi all,

I am having problem in ASP.NET and I hope I can find solution in here.

While studying the "MCAD/MCSD Training Kit-Developing Web Applications
with Microsoft Visual Basic .NET and Microsoft Visual C# .NET" Training kit
I get an error. Here is the error.
-------------------------------------------------------------------------- -------------------------------------------------------------------
Error: Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
Line 36:
Line 37: ' Get path.
Line 38: strPath = Session("C:\Inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c").ToString()
Line 39: ' If this is not a post-back event.
Line 40: If Not IsPostBack Then


Source File:
c:\inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c\FileManager.aspx.vb Line:
38
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Chapter_04c.FileManager.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c\FileManager.aspx.vb:38
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731

-------------------------------------------------------------------------- --------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
-------------------------------------------------------------------------- ------------------------------------------------------------------



I also have this information in my hand:)
modify privileges in the application's root folder. By default, the ASPNET
user account has only read and execute privileges. See Chapter 9, "Building
and Deploying Web Applications," for information about how to assign
security privileges in the application folder.
----------------------------------------------


Currently I am accesing with VS Studion.Net account so ASPNET account is not a problem.

My problem is how to get the path in ASP.NET. And this is not a PostBack event.

Line 37: ' Get path.
Line 38: strPath = Session("C:\Inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c").ToString()
Line 39: ' If this is not a post-back event.
Line 40: If Not IsPostBack Then

Can anyone tell me where I can find information to correct the problem.
But I am more than happy to write the correct code that if anyone knows the
answer.
 
S

Scott M.

And/Or you don't need to call .ToString() anyway because Session isn't
data-type aware anyway. Everything in Session is a string.


Marina said:
This is because a session variable with that name hasn't been created, so
session("...") gets evaluated to Nothing. When you call .ToString() on
Nothing, you get a NullReferenceException. You need to make sure that
session variable is there before you try to do anything with it.

GC said:
Hi all,

I am having problem in ASP.NET and I hope I can find solution in here.

While studying the "MCAD/MCSD Training Kit-Developing Web Applications
with Microsoft Visual Basic .NET and Microsoft Visual C# .NET" Training kit
I get an error. Here is the error.
--------------------------------------------------------------------------
set
to an instance of an object.
Source Error:
Line 36:
Line 37: ' Get path.
Line 38: strPath = Session("C:\Inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c").ToString()
Line 39: ' If this is not a post-back event.
Line 40: If Not IsPostBack Then


Source File:
c:\inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c\FileManager.aspx.vb Line:
38
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Chapter_04c.FileManager.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c\FileManager.aspx.vb:38
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
ASP.NET Version:1.1.4322.573

--------------------------------------------------------------------------
------------------------------------------------------------------
I also have this information in my hand:)
modify privileges in the application's root folder. By default, the ASPNET
user account has only read and execute privileges. See Chapter 9, "Building
and Deploying Web Applications," for information about how to assign
security privileges in the application folder.
----------------------------------------------


Currently I am accesing with VS Studion.Net account so ASPNET account is not a problem.

My problem is how to get the path in ASP.NET. And this is not a PostBack event.

Line 37: ' Get path.
Line 38: strPath = Session("C:\Inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c").ToString()
Line 39: ' If this is not a post-back event.
Line 40: If Not IsPostBack Then

Can anyone tell me where I can find information to correct the problem.
But I am more than happy to write the correct code that if anyone knows the
answer.

I thank you in advance.

Rgds,
GC
 
M

Marina

That isn't true. You can store objects in Session, and in fact, they come
back as such. You need to cast what you get from session to whatever
datatype is appropriate.

Scott M. said:
And/Or you don't need to call .ToString() anyway because Session isn't
data-type aware anyway. Everything in Session is a string.


Marina said:
This is because a session variable with that name hasn't been created, so
session("...") gets evaluated to Nothing. When you call .ToString() on
Nothing, you get a NullReferenceException. You need to make sure that
session variable is there before you try to do anything with it.

GC said:
Hi all,

I am having problem in ASP.NET and I hope I can find solution in here.

While studying the "MCAD/MCSD Training Kit-Developing Web Applications
with Microsoft Visual Basic .NET and Microsoft Visual C# .NET" Training kit
I get an error. Here is the error.
-------------------------------------------------------------------------- the
current web request.
Exception Details: System.NullReferenceException: Object reference not
set
to an instance of an object.
Source Error:
Line 36:
Line 37: ' Get path.
Line 38: strPath = Session("C:\Inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c").ToString()
Line 39: ' If this is not a post-back event.
Line 40: If Not IsPostBack Then


Source File:
c:\inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c\FileManager.aspx.vb Line:
38
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Chapter_04c.FileManager.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c\FileManager.aspx.vb:38
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731

--------------------------------------------------------------------------ASP.NET Version:1.1.4322.573

--------------------------------------------------------------------------
------------------------------------------------------------------



I also have this information in my hand:)
and
modify privileges in the application's root folder. By default, the ASPNET
user account has only read and execute privileges. See Chapter 9, "Building
and Deploying Web Applications," for information about how to assign
security privileges in the application folder. is
not a problem.
My problem is how to get the path in ASP.NET. And this is not a
PostBack
event.
Line 37: ' Get path.
Line 38: strPath = Session("C:\Inetpub\wwwroot\ASPNETEXAMPLES\Chapter-04c").ToString()
Line 39: ' If this is not a post-back event.
Line 40: If Not IsPostBack Then

Can anyone tell me where I can find information to correct the
problem.
But I am more than happy to write the correct code that if anyone knows the
answer.

I thank you in advance.

Rgds,
GC
 
G

Guest

Hi

Thank you. I already created sesion state in Sign On page, and I was trying to test the page that I should start from SignOn page not other

Now everythings is works perfect

Thank you

Rgds
GC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top