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, -
- Server Error in '/Alfi/invoice generation/WebApplication1' Application.
-
- Object reference not set to an instance of an object.
-
-
[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.
-
- Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
-
- Source Error:
-
-
Line 41: // tryLine 42: // {[color=red]Line 43: if(Session["UnAuthorised"].ToString()!="")[/color]Line 44: {Line 45: lblPlzLgn.Visible=true;
- [font=Verdana]Source File: [/font]\\avsystems11\alfi\invoice generation\webapplication1\scripts\login.aspx.cs[font=Verdana] Line: [/font]43
-
- [font=Verdana]Stack Trace:[/font]
-
-
[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
-
- [font=Verdana]Version Information:[/font] Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573 [/font]
-
my coding which caused this error is -
[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)
-
-
{
-
-
lblPlzLgn.Visible=[/size][size=2][color=#0000ff]false[/color][/size][size=2];
-
-
lblSessionExp.Visible=[/size][size=2][color=#0000ff]false[/color][/size][size=2];
-
-
Session["text"]="";
-
-
Session["Alert"]="";
-
-
[/size][size=2][/size][size=2][color=#0000ff]if[/color][/size][size=2](Session["UnAuthorised"].ToString()!="")
-
-
{
-
-
lblPlzLgn.Visible=[/size][size=2][color=#0000ff]true[/color][/size][size=2];
-
-
Session["UnAuthorised"]="";
-
-
}
-
-
[/size][size=2][color=#0000ff]else
-
-
[/color][/size][size=2]{
-
some conditions();
-
}
-
[/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,
9 1907
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
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
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
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... -
private void Page_Load(object sender, System.EventArgs e)
-
{
-
-
lblPlzLgn.Visible=false;
-
-
lblSessionExp.Visible=false;
-
Session("text")="";
-
Session("Alert")="";
-
-
if(Session("UnAuthorised")==NULL)
-
{
-
lblPlzLgn.Visible=true;
-
Session["UnAuthorised"]="";
-
}else
-
{
-
some conditions();
-
}
-
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
Try something like this... -
private void Page_Load(object sender, System.EventArgs e)
-
{
-
-
lblPlzLgn.Visible=false;
-
-
lblSessionExp.Visible=false;
-
Session("text")="";
-
Session("Alert")="";
-
-
if(Session("UnAuthorised")==NULL)
-
{
-
lblPlzLgn.Visible=true;
-
Session["UnAuthorised"]="";
-
}else
-
{
-
some conditions();
-
}
-
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
Try something like this... -
private void Page_Load(object sender, System.EventArgs e)
-
{
-
-
lblPlzLgn.Visible=false;
-
-
lblSessionExp.Visible=false;
-
Session("text")="";
-
Session("Alert")="";
-
-
if(Session("UnAuthorised")==NULL)
-
{
-
lblPlzLgn.Visible=true;
-
Session["UnAuthorised"]="";
-
}else
-
{
-
some conditions();
-
}
-
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.
hi frinny,
the problem is solved by replacing '(' with '['. now its working fine. thanks for the help.
Glad to have helped
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: -
[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]
-
[size=2]{
-
lblPlzLgn.Visible=[/size][size=2][color=#0000ff]false[/color][/size][size=2];[/size]
-
[size=2][color=#0000ff] if[/color][/size][size=2](Session["UnAuthorised"]!=[/size][size=2][color=#0000ff]null[/color][/size][size=2])[/size]
-
[size=2] {[/size]
-
[size=2] lblPlzLgn.Visible=[/size][size=2][color=#0000ff]true[/color][/size][size=2];[/size]
-
[size=2] Session["UnAuthorised"]="";[/size]
-
[size=2] }[/size]
-
[size=2]}[/size]
-
[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]
-
[size=2]{[/size]
-
[size=2][size=2] Session["text"]=TextBox1.Text;[/size][/size]
-
[size=2][size=2] TextBox1.Text="";[/size][/size]
-
[size=2][size=2] TextBox2.Text="";[/size][/size]
-
[size=2][size=2] Response.Redirect ("SecondPage.aspx");[/size][/size]
-
[size=2][size=2]}[/size][/size]
-
[/size]
Second Page: -
[size=2][color=#0000ff]if[/color][/size][size=2](Session["text"]!=null)[/size]
-
[size=2]{[/size]
-
[size=2]alert(); [/size]
-
[size=2]}[/size]
-
[size=2][color=#0000ff]else
-
[/color][/size][size=2]{
-
[size=2]Session["UnAuthorised"]="UnAuthorised";[/size]
-
Response.Redirect("Login.aspx");
-
}
-
[/size]
can u help me in solving this problem
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. -
private void Page_Load(object sender, System.EventArgs e)
-
{
-
lblPlzLgn.Visible=false;
-
-
if(Session["UnAuthorised"]!=null)
-
{
-
lblPlzLgn.Visible=true;
-
Session["UnAuthorised"]="";
-
}
-
}
-
private void Button1_Click(object sender, System.EventArgs e)
-
{
-
Session["text"]=TextBox1.Text;
-
TextBox1.Text="";
-
TextBox2.Text="";
-
/* You should check to see if the user's credentials are valid
-
here before Redirecting them to the SecondPage.aspx.
-
Here I would do something like:
-
-
if(userCredentialsAreValid()==true)
-
{ //userCredentialsAreValid() is the function
-
//that returns true if the user's credentials are valid and false otherwise.
-
Session["UnAuthorized"]=false;
-
Response.Redirect ("SecondPage.aspx");
-
}
-
else
-
{
-
Session["UnAuthorized"]=true;
-
}
-
*/
-
}
-
-
-
if(Session["UnAuthroised"]==null)
-
{
-
Response.Redirect("Login.aspx");
-
}
-
else if (Session["UnAuthorized"]==true)
-
{
-
Response.Redirect("Login.aspx");
-
}
-
else
-
{
-
if(Session["text"]!=null)
-
{
-
alert();
-
}
-
else
-
{
-
Session["UnAuthorised"]=true;
-
Response.Redirect("Login.aspx");
-
}
-
}
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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 -...
|
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)....
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...)
...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
| |