Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2007, 11:15 AM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deb1980
Default How to check for a valid session?

Hi,

How to check for a valid session?

Regards,
Debashis

__________________
---
Best regards,

Debashis
http://debashis80.spaces.live.com/
 
Old March 16th, 2007, 11:21 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

...What is a valid session? A session that hasn't expired?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 16th, 2007, 11:27 AM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deb1980
Default

Hi,

Thanks for the reply.
Yep i understand that part. However i want to know when an user directly types a link on the address bar, the aspx page should first check for a valid user id else it should redirect the user back to the login page.

What I is:

<%
    If (Session("userid").ToString = "") Then
        Response.Redirect("default.aspx")
    End If
%>

Could you please help?

regards,
Debashis


 
Old March 16th, 2007, 11:40 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok that should work? What is the problem you are having with the code?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 16th, 2007, 11:43 AM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deb1980
Default

I am getting an error:

Server Error in '/Accountsystem' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
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 1: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
Line 2: <%
Line 3: If (Session("userid").ToString = "") Then
Line 4: Response.Redirect("default.aspx")
Line 5: End If



Previously to store data in session, I used:

Session("userid") = rs(0)


---
Best regards,

Debashis
 
Old March 16th, 2007, 11:52 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ahh. You can try 3 different methods.

Method 1:
If Session("userid") is Nothing then
Response.Redirect("default.aspx")
End If

Method 2
If Session("userID") = "" then
Response.Redirect("default.aspx")
End If

Method 3
If Session("userID") = "" OR Session("userID") is Nothing then
Response.Redirect("default.aspx")
End If

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 16th, 2007, 11:59 AM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deb1980
Default

Thanks man - working cool!


---
Best regards,

Debashis
 
Old March 16th, 2007, 12:03 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No problem glad it worked out for you.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 24th, 2007, 06:27 PM
Authorized User
 
Join Date: Apr 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just wanted to add to this topic about checking for nulls in C#. I found out it is very easy to use String.IsNullOrEmpty(your variable you are testing).

It will check to see if the object is null or empty and return true if is or false if not.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Connect to VSS check-in Check-out Programatically rhd110 General .NET 6 August 12th, 2007 07:46 AM
How to check server performance for a Session savan_thakkar ASP.NET 1.0 and 1.1 Professional 0 September 18th, 2006 07:56 AM
check whether a particular session exists or not chayanvinayak PHP How-To 1 May 1st, 2006 04:09 PM
Check for existence of a session variable apd8x ASP.NET 1.0 and 1.1 Basics 2 November 12th, 2003 11:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.