Click here to Skip to main content
Licence 
First Posted 11 Aug 2003
Views 234,330
Bookmarked 73 times

ASP.NET Session Login Without Cookies

By | 11 Aug 2003 | Article
Easiest way to authenticate users without cookies.

Introduction

The following describes the easiest way I have found to force users to log into an ASP.NET website for each session but not require them to accept cookies. You must do the following things.

  1. Create a Web.config file with the appropriate entries to allow session state management.
  2. Create a well formed Global.asax file with the code below included in it.
  3. Create a login page to authenticate users against a database or whatever method you desire.

Code usage

Required Code in the Global.asax

' Fires when the session is started and sets the default loggedin state to ""
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Session("Loggedin") = ""
CheckLoggedIn()
End Sub
' Called when the request has been process by the Request Handler and 
' HttpSessionState is available [This is the key piece of code that forces 
' the user is login check with each page request]
Sub Application_OnPostRequestHandlerExecute()
CheckLoggedIn()
End Sub
'Check that the user is logged in.
Sub CheckLoggedIn()
'If the user is not logged in and you are not currently on the Login Page.
If Session("LoggedIn") = "" And InStr(Request.RawUrl, "Login.aspx") = 0 Then
Response.Redirect("~/Login/Login.aspx")
End If
End Sub

Finally create a Login.aspx file that authenticates the user. If the user is allowed in, set: Session("Loggedin") = "Yes"

That's all there is to it. Hope this helps! Enjoy!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Wraith01



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 3 PinmemberAmir Mahfoozi20:58 20 Dec '11  
GeneralMy vote of 1 Pinmembernirav_k_mehta1:22 27 Dec '10  
Questionhow session we create for name at all pages Pinmemberimadbaloch4:30 13 Apr '09  
AnswerRe: how session we create for name at all pages Pinmembermauji21:27 11 Jul '09  
QuestionWhat is the appropriate code in Web.Config PinmemberNaveen Mahesh19:01 29 Jul '07  
Questionhow to create login? Pinmembercaabool_oo2:13 5 Apr '07  
Generallogin form Pinmembernon221:28 19 Apr '05  
GeneralRe: login form Pinmemberbalazs_hideghety21:53 8 Jun '05  
Generalshop_store PinsussAnonymous22:57 17 Apr '05  
GeneralRe: shop_store PinmemberWraith013:33 18 Apr '05  
GeneralRawUrl problem PinsussIsaac Franco Fernandes8:30 11 Jan '05  
GeneralRe: RawUrl problem PinmemberWraith019:25 11 Jan '05  
QuestionRe: RawUrl problem Pinmembersamdani_basha0:17 9 Sep '07  
AnswerRe: RawUrl problem Pinmemberjoel8518:54 28 Nov '08  
GeneralDeserves a better rating PinstaffNishant S1:06 29 Oct '03  
Generalweb.config in subdirectory PinmemberMajid Shahabfar23:59 26 Oct '03  
GeneralNot exactly PinmemberPhilip Patrick4:15 13 Aug '03  
GeneralRe: Not exactly PinmemberZek3vil5:17 13 Aug '03  
GeneralRe: Not exactly PinmemberPhilip Patrick5:27 13 Aug '03  
GeneralCookieless = no good Pinmemberdog_spawn5:28 13 Aug '03  
GeneralRe: Cookieless = no good PinmemberPhilip Patrick20:28 20 Aug '03  
GeneralRe: Cookieless = no good Pinmemberdog_spawn21:33 20 Aug '03  
GeneralRe: Cookieless = no good PinmemberDavid M. Auld16:54 30 Aug '03  
GeneralYes Pinmemberdog_spawn3:35 31 Aug '03  
GeneralRe: Not exactly PinmemberLennybacon6:38 19 Aug '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 12 Aug 2003
Article Copyright 2003 by Wraith01
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid