toddVance.Com

programming notes…

toddVance.Com Rss
  • Home
  • XNA
  • Silverlight

Apr

28

2010

Make sure to turn off page caching when writing a login page

Posted by

Category : C#, VB.Net

Tags: .Net, C#, cache, Login, VB.Net

SCENARIO:
Created a simple login that checked user name and password against a database and then sent user to the proper page if verified. (also writing a ‘logged in’ session variable)

Within the pages Page_Load event, I check for the proper session variable and if not present send them back to login screen.

Additionally, I added a logout link that wiped the variable and sent them back to login….

THING all appeared to work great… UNTIL I tried to navigate straight to a page AFTER logging out. The page was able to be accessed EVEN though I had logged out AND my Page_Load event was not even getting called.
====

REASON/SOLUTION:
The pages were being cached and therefore did not need to check the Page_Load event which would have caught the fact that the user was not properly logged in…. The solution is to place the following code in your Load event.

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);

** This is not a proper solution for a large solution with a lot of pages but for this purpose I only had one Default page with user controls … if you have many pages you should use the auth ticket option.

May

11

2009

LoginControl notes

Posted by

Category : ASP.Net, VB.Net

Tags: ASP.Net, Login, VB.Net

Quick points when working in code behind with a LoginControl (or things in it)

To find the controls within the login control you need to make a variable to hold the control using the .FindControl method like so:

Dim passWord As TextBox = LoginControl1.FindControl(“Password”)

*Now you can use it…  ( passWord.Enabled = true)

———

To fill in a password control from code behind, calling it’s .text does not work.  You need to do the following: (this will fill it in WITH the value masked)

passWord.Attributes.Add(“value”, “admin1″)    * thanks to Third software for this clue

  •  
  • Categories

    • ADO / SQL
    • ASP.Net
    • C#
    • JQuery/JScript
    • Off-Topic
    • Other techs
    • Uncategorized
    • VB.Net
    • XNA/Game programming
  • Sponsors:



    Upvote this page for
    ".Net"
    at a new search engine
     

    toddvance.com = a great repository of snippets and code examples for .Net, JQuery, PHP, and more!
  • Random Quote

    Democracy and socialism have nothing in common
    but one word, equality. But notice the difference: while democracy seeks equality in liberty, socialism seeks equality in restraint and servitude.
    — Alexis de Tocqueville

  • Sponsors:

  • Tags

    .Net ADO / SQL API Applications ASP.Net C# Church Collections conversion datatable Dictionary embedded resources escape Excel game design Google html Javascript JQuery/JScript JQuery/JScript Login lowerCase Macros memorystream Nugget Nuggets nullables Off-Topic politics Programming SQL String stringreader stringwriter syntax types upperCase vb VB.Net visual studio Web XML XNA XNA/Game programming zip
  • Microsoft Store
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Good stuff...

    • Digital Fuel
    • Dustin Diaz – Javascript/YUI
    • Equipped 2 Live
    • Matt Snider – Javascript guru
    • Nick Gravelyn – XNA Guru
    • Reimer Grootjan – XNA MVP and great teacher
    • XNA Development
  • toddVance.Com

    © All Rights Reserved. toddVance.Com

    Wordpress Themes Designed by WebDesignHive.com