473,387 Members | 1,722 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,387 software developers and data experts.

Object reference

I get an error message:
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

I get an error in line:
If Session("user") Is Nothing Then....

What could be wrong?


Nov 18 '05 #1
5 1155
Apparently, the Session doesn't exist in the context of the line you posted.

--
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"simon" <si*********@stud-moderna.si> wrote in message
news:e4**************@TK2MSFTNGP12.phx.gbl...
I get an error message:
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

I get an error in line:
If Session("user") Is Nothing Then....

What could be wrong?


Nov 18 '05 #2
Hi,
I get an error in line:
If Session("user") Is Nothing Then....

What could be wrong?


Session object is null (Nothing).

1) Check <sessionState> element in your Web.config file.
2) Make sure that you retrieve it correctly.

--
______________________________
With best wishes, Arthur Nesterovsky
Please visit my home page:
http://www.nesterovsky-bros.com

Nov 18 '05 #3

Hi,

If I use session object in user control(aspx page), it doesn't work.
If I write the same code in default.aspx then everything is fine.

In past I have code and all my functions in include.asp page, which I
included on all my pages.
I had line:
If Session("user") Is Nothing Then
response.redirect "login.asp"
End If

Now I move all my functions to user control (by the book) and register it on
all my pages - approximate the similar like with include.
But if the session won't work, I don't want to write line with session
checking on all my pages.
Should I use include statement(which is past from asp) or is there some
other way?

Thank you,
Simon

"Arthur Nesterovsky" <ar********************@nesterovsky-bros.com> wrote in
message news:uH**************@TK2MSFTNGP09.phx.gbl...
Hi,
I get an error in line:
If Session("user") Is Nothing Then....

What could be wrong?


Session object is null (Nothing).

1) Check <sessionState> element in your Web.config file.
2) Make sure that you retrieve it correctly.

--
______________________________
With best wishes, Arthur Nesterovsky
Please visit my home page:
http://www.nesterovsky-bros.com

Nov 18 '05 #4
Hi,
I had line:
If Session("user") Is Nothing Then
response.redirect "login.asp"
End If

Now I move all my functions to user control (by the book) and register it on all my pages - approximate the similar like with include.


Try to check

HttpContext.Current.Session("user") instead.

--
______________________________
With best wishes, Arthur Nesterovsky
Please visit my home page:
http://www.nesterovsky-bros.com

Nov 18 '05 #5
I have control leviMenu.ascx, where I define session:
If HttpContext.Current.Session("user") Is Nothing Then
Dim uporabnik(2)
uporabnik(0) = "1"
uporabnik(1) = "Simon Zupan"
uporabnik(2) = "2"
Session("user") = uporabnik
End If

Then I register it on the page:

<%@ Register TagPrefix ="Menu" TagName = "LeviMenu" Src =
"userControls\leviMenu.ascx"%>

then use it on page:

<menu:leviMenu runat="server" ID="Levimenu1"></menu:leviMenu>

Then on the same page in Private Sub Page_Load event, I'm reading the value
from session:

HttpContext.Current.Session("user")(0)

And I gett an error message:

System.NullReferenceException: Object variable or With block variable not
set.

The session object is not recognized.

How can I solve this problem?

I have session object in user control because it's registered on all pages.
I can write the session code on each page separeted, it works than, but than
I don't have the code on one place, it doesn't make any sence.

Thank you,
Simon

"Arthur Nesterovsky" <ar********************@nesterovsky-bros.com> wrote in
message news:Oz**************@TK2MSFTNGP09.phx.gbl...
Hi,
I had line:
If Session("user") Is Nothing Then
response.redirect "login.asp"
End If

Now I move all my functions to user control (by the book) and register
it on
all my pages - approximate the similar like with include.


Try to check

HttpContext.Current.Session("user") instead.

--
______________________________
With best wishes, Arthur Nesterovsky
Please visit my home page:
http://www.nesterovsky-bros.com

Nov 18 '05 #6

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

Similar topics

11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: helloitsme | last post by:
Hello All! I am using access object to run a module in my access database. The module runs fine. However, the database does not get closed even though I have tried many things to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.