473,387 Members | 1,504 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.

session error

271 100+
hi,
i have used session in my .net project. its version is 1.1, when ever i load that page i get the following error,
Expand|Select|Wrap|Line Numbers
  1.  
  2. Server Error in '/Alfi/invoice generation/WebApplication1' Application. 
  3.  
  4. Object reference not set to an instance of an object. 
  5.  
  6. [font=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  7.  
  8. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
  9.  
  10. Source Error: 
  11.  
  12. Line 41: //            tryLine 42: //            {[color=red]Line 43:                 if(Session["UnAuthorised"].ToString()!="")[/color]Line 44:                 {Line 45:                     lblPlzLgn.Visible=true;
  13. [font=Verdana]Source File: [/font]\\avsystems11\alfi\invoice generation\webapplication1\scripts\login.aspx.cs[font=Verdana]    Line: [/font]43 
  14.  
  15. [font=Verdana]Stack Trace:[/font] 
  16.  
  17. [NullReferenceException: Object reference not set to an instance of an object.]   AutomaticInvoiceGeneration.Login.Page_Load(Object sender, EventArgs e) in \\avsystems11\alfi\invoice generation\webapplication1\scripts\login.aspx.cs:43   System.Web.UI.Control.OnLoad(EventArgs e) +67   System.Web.UI.Control.LoadRecursive() +35   System.Web.UI.Page.ProcessRequestMain() +731
  18.  
  19. [font=Verdana]Version Information:[/font] Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573 [/font]
  20.  
my coding which caused this error is
Expand|Select|Wrap|Line Numbers
  1. [size=2][color=#0000ff]private[/color][/size][size=2] [/size][size=2][color=#0000ff]void[/color][/size][size=2] Page_Load([/size][size=2][color=#0000ff]object[/color][/size][size=2] sender, System.EventArgs e)
  2.  
  3. {
  4.  
  5. lblPlzLgn.Visible=[/size][size=2][color=#0000ff]false[/color][/size][size=2];
  6.  
  7. lblSessionExp.Visible=[/size][size=2][color=#0000ff]false[/color][/size][size=2];
  8.  
  9. Session["text"]="";
  10.  
  11. Session["Alert"]="";
  12.  
  13. [/size][size=2][/size][size=2][color=#0000ff]if[/color][/size][size=2](Session["UnAuthorised"].ToString()!="")
  14.  
  15. {
  16.  
  17. lblPlzLgn.Visible=[/size][size=2][color=#0000ff]true[/color][/size][size=2];
  18.  
  19. Session["UnAuthorised"]="";
  20.  
  21. }
  22.  
  23. [/size][size=2][color=#0000ff]else
  24.  
  25. [/color][/size][size=2]{
  26. some conditions();
  27. }
  28. [/size]
what could be the cause of this error. i know that this error can be caught using exceptions, but my problem is i need to use nested try commands. as a result of this problem it is not entering into the nested region and throws exception. how to solve this problem.

thanks,
Feb 7 '07 #1
9 1907
Frinavale
9,735 Expert Mod 8TB
hi,
i have used session in my .net project. its version is 1.1, when ever i load that page i get the following error,
...
what could be the cause of this error. i know that this error can be caught using exceptions, but my problem is i need to use nested try commands. as a result of this problem it is not entering into the nested region and throws exception. how to solve this problem.

thanks,

Hi there Karthi,

You're trying to compare your session variable "UnAuthorised" to "".
I'm assuming that the first time the user comes to the page this variable hasn't been set to anything. Then when you try to compare it to "" you're getting your Null Reference error because it hasn't yet been defined.

Before trying to do this comparison, check to see if this variable has been defined. In other words check to see that this variable is not Null or Nothing before comparing it to "" . If it is nothing you should deal with the situation accordingly (I'm assuming the person isn't authorized).

Hope this helps

-Frinny
Feb 7 '07 #2
karthi84
271 100+
Hi there Karthi,

You're trying to compare your session variable "UnAuthorised" to "".
I'm assuming that the first time the user comes to the page this variable hasn't been set to anything. Then when you try to compare it to "" you're getting your Null Reference error because it hasn't yet been defined.

Before trying to do this comparison, check to see if this variable has been defined. In other words check to see that this variable is not Null or Nothing before comparing it to "" . If it is nothing you should deal with the situation accordingly (I'm assuming the person isn't authorized).

Hope this helps

-Frinny
thanks finnay for the idea. let me try and reply u
Feb 8 '07 #3
karthi84
271 100+
Hi there Karthi,

You're trying to compare your session variable "UnAuthorised" to "".
I'm assuming that the first time the user comes to the page this variable hasn't been set to anything. Then when you try to compare it to "" you're getting your Null Reference error because it hasn't yet been defined.

Before trying to do this comparison, check to see if this variable has been defined. In other words check to see that this variable is not Null or Nothing before comparing it to "" . If it is nothing you should deal with the situation accordingly (I'm assuming the person isn't authorized).

Hope this helps

-Frinny
hi frinny,
i tried it but it was not helping me. can u get me with an example for this. my requirement is
1. if an unauthorized person goes directly to 2nd page without logging in he is to be identified and a message is to be given. so i used one session from the login page.
2. one more session to identify the session time out and get a message in the login page
Feb 8 '07 #4
Frinavale
9,735 Expert Mod 8TB
hi frinny,
i tried it but it was not helping me. can u get me with an example for this. my requirement is
1. if an unauthorized person goes directly to 2nd page without logging in he is to be identified and a message is to be given. so i used one session from the login page.
2. one more session to identify the session time out and get a message in the login page
Try something like this...
Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2. {
  3.  
  4. lblPlzLgn.Visible=false;
  5.  
  6. lblSessionExp.Visible=false;
  7. Session("text")="";
  8. Session("Alert")="";
  9.  
  10. if(Session("UnAuthorised")==NULL)
  11. {
  12.     lblPlzLgn.Visible=true;
  13.     Session["UnAuthorised"]="";
  14. }else
  15. {
  16.     some conditions();
  17. }
  18.  
What language are you using? C#?

Looking at your code again I'm realizing that not only are you trying to compare NULL to "" but also you were trying to do a toString() on a variable that was null.

Try this and let me know if it helps out

-Frinny
Feb 8 '07 #5
karthi84
271 100+
Try something like this...
Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2. {
  3.  
  4. lblPlzLgn.Visible=false;
  5.  
  6. lblSessionExp.Visible=false;
  7. Session("text")="";
  8. Session("Alert")="";
  9.  
  10. if(Session("UnAuthorised")==NULL)
  11. {
  12. lblPlzLgn.Visible=true;
  13. Session["UnAuthorised"]="";
  14. }else
  15. {
  16. some conditions();
  17. }
  18.  
What language are you using? C#?

Looking at your code again I'm realizing that not only are you trying to compare NULL to "" but also you were trying to do a toString() on a variable that was null.

Try this and let me know if it helps out

-Frinny
hi frinny,
i tried that code but results me in an error. the error message is
'System.Web.UI.Page.Session' denotes a 'property' where a 'method' was expected.

how to solve this problem
Feb 9 '07 #6
karthi84
271 100+
Try something like this...
Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2. {
  3.  
  4. lblPlzLgn.Visible=false;
  5.  
  6. lblSessionExp.Visible=false;
  7. Session("text")="";
  8. Session("Alert")="";
  9.  
  10. if(Session("UnAuthorised")==NULL)
  11. {
  12. lblPlzLgn.Visible=true;
  13. Session["UnAuthorised"]="";
  14. }else
  15. {
  16. some conditions();
  17. }
  18.  
What language are you using? C#?

Looking at your code again I'm realizing that not only are you trying to compare NULL to "" but also you were trying to do a toString() on a variable that was null.

Try this and let me know if it helps out

-Frinny
hi frinny,
the problem is solved by replacing '(' with '['. now its working fine. thanks for the help.
Feb 9 '07 #7
Frinavale
9,735 Expert Mod 8TB
hi frinny,
the problem is solved by replacing '(' with '['. now its working fine. thanks for the help.
Glad to have helped
Feb 9 '07 #8
karthi84
271 100+
Glad to have helped
hi frinny,

now i get a lot of problem in my page. when i go to other pages whithout logging in using the url, it should be redirected stating please login. but for me that is not working.
similarly when i logoff after loging in this message is displayed. the below shown are the two different page codings. please help me in this,

Login Page:

Expand|Select|Wrap|Line Numbers
  1. [size=2][color=#0000ff]private[/color][/size][size=2] [/size][size=2][color=#0000ff]void[/color][/size][size=2] Page_Load([/size][size=2][color=#0000ff]object[/color][/size][size=2] sender, System.EventArgs e)[/size]
  2. [size=2]{
  3.    lblPlzLgn.Visible=[/size][size=2][color=#0000ff]false[/color][/size][size=2];[/size]
  4. [size=2][color=#0000ff]     if[/color][/size][size=2](Session["UnAuthorised"]!=[/size][size=2][color=#0000ff]null[/color][/size][size=2])[/size]
  5. [size=2]     {[/size]
  6. [size=2]        lblPlzLgn.Visible=[/size][size=2][color=#0000ff]true[/color][/size][size=2];[/size]
  7. [size=2]       Session["UnAuthorised"]="";[/size]
  8. [size=2]     }[/size]
  9. [size=2]}[/size]
  10. [size=2][size=2][color=#0000ff]private[/color][/size][size=2] [/size][size=2][color=#0000ff]void[/color][/size][size=2] Button1_Click([/size][size=2][color=#0000ff]object[/color][/size][size=2] sender, System.EventArgs e)[/size]
  11. [size=2]{[/size]
  12. [size=2][size=2]     Session["text"]=TextBox1.Text;[/size][/size]
  13. [size=2][size=2]     TextBox1.Text="";[/size][/size]
  14. [size=2][size=2]     TextBox2.Text="";[/size][/size]
  15. [size=2][size=2]     Response.Redirect ("SecondPage.aspx");[/size][/size]
  16. [size=2][size=2]}[/size][/size]
  17. [/size]
Second Page:

Expand|Select|Wrap|Line Numbers
  1. [size=2][color=#0000ff]if[/color][/size][size=2](Session["text"]!=null)[/size]
  2. [size=2]{[/size]
  3. [size=2]alert(); [/size]
  4. [size=2]}[/size]
  5. [size=2][color=#0000ff]else
  6. [/color][/size][size=2]{
  7. [size=2]Session["UnAuthorised"]="UnAuthorised";[/size]
  8. Response.Redirect("Login.aspx");
  9. }
  10. [/size]
can u help me in solving this problem
Feb 10 '07 #9
Frinavale
9,735 Expert Mod 8TB
hi frinny,

now i get a lot of problem in my page. when i go to other pages whithout logging in using the url, it should be redirected stating please login. but for me that is not working.
similarly when i logoff after loging in this message is displayed. the below shown are the two different page codings. please help me in this,

Login Page:
...

can u help me in solving this problem

Hi Karthi,

I'm not quite sure what you are trying to do with the code you posted.

First of all, aren't you supposed to check the user's credentials before passing them on to the second page?

Secondly, is your lblPlzLgn an error label or the actual text for prompting the user?

You'll have to better explain what exactly is going on.
What happens to your site when the error occurs?
Does it redirect when its not supposed to?
Does it not redirect when it is supposed to?


Looking at your code I don't see any sort of user validation. I'd validate the user on the first page before allowing them to go on the second page.

Eg. I'd set the Session["UnAuthorised"] variable to true if the user's credentials weren't valid and I'd set the variable to "false" if the user's credentials were valid. Then on every page I'd check to see if the Session["UnAuthroised"] variable is null or if it's true...and if so I wouldn't do any processing on that page, but instead redirect the user back to the starting page.


Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2. {
  3.        lblPlzLgn.Visible=false;
  4.  
  5.      if(Session["UnAuthorised"]!=null)
  6.      {
  7.         lblPlzLgn.Visible=true;
  8.            Session["UnAuthorised"]="";
  9.      }
  10. }
  11. private void Button1_Click(object sender, System.EventArgs e)
  12. {
  13.      Session["text"]=TextBox1.Text;
  14.      TextBox1.Text="";
  15.      TextBox2.Text="";
  16.     /* You should check to see if the user's credentials are valid 
  17. here before Redirecting them to the SecondPage.aspx.  
  18. Here I would do something like:
  19.  
  20. if(userCredentialsAreValid()==true)
  21. { //userCredentialsAreValid() is the function 
  22.  //that returns true if the user's credentials are valid and false otherwise.
  23.          Session["UnAuthorized"]=false;
  24.      Response.Redirect ("SecondPage.aspx");
  25. }
  26. else
  27. {
  28.          Session["UnAuthorized"]=true;
  29. }
  30. */
  31. }
  32.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. if(Session["UnAuthroised"]==null)
  3. {
  4.             Response.Redirect("Login.aspx");
  5. }
  6. else if (Session["UnAuthorized"]==true)
  7. {
  8.            Response.Redirect("Login.aspx");
  9. }
  10. else
  11. {
  12.           if(Session["text"]!=null)
  13.           {
  14.               alert(); 
  15.           }
  16.           else
  17.          {
  18.               Session["UnAuthorised"]=true;
  19.                 Response.Redirect("Login.aspx");
  20.          }
  21. }
  22.  
I don't know if any of the above suggestions are going to help because I'm not exactly sure what the problem is.

-Frinny
Feb 12 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Ottar | last post by:
I've made a program sorting incomming mail in public folder. The function runs every minute by using the form.timer event. In Access XP it runs for weeks, no problem. Access 2003 runs the same...
9
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use -...
7
by: Spencer H. Prue | last post by:
Hello!, I have a using system.web.sessionstate directive one the top of each of two web pages. On the first page I have the dataadapter, dataconnection, and dataset (also in the component tray)....
2
by: Gavin Lyons via .NET 247 | last post by:
Hello, I'm writing a newsletter application which uses backgroundthreading. I'm using Session variable to report on progresswhile it loops through a dataset. The 'Status.aspx' pagerefreshes every...
2
by: Dave | last post by:
I have an application running on a 3 server webfarm running Windows 2003 with SQLServer Session state. After running for several hours, I started getting the following error. When I access each...
11
by: Jerry | last post by:
I'm using this code: Dim strName For Each strName in Session.Contents Response.Write strName & " - " & Session.Contents(strName) & "<BR>" Next If I only do a response.write strName, it shows...
5
by: lyealain | last post by:
<% If Session("username") = "" Then Response.Redirect("/CLS/Login.asp") End If Dim conn Dim connectstr Dim db_name, db_username, db_userpassword Dim db_server Dim res
7
by: David Lozzi | last post by:
Howdy, I'm trying to capture the session end event. I put a spot of code in the Session_End event in the Global.asax.vb file. The function simply writes to a database table logging the event. I...
6
by: ChrisAtWokingham | last post by:
I have been struggling with unexpected error messages on an ASP.NET system, using SQL and C#. The application draws organisation charts, based on data stored in the SQL database. Some of the chart...
4
by: Cirene | last post by:
In my web.config I added <pages enableSessionState="true">. In each of my pages I also added EnableSessionState="True" to the Page declaration. (I didn't think this was necessary, but...) ...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.