Click here to Skip to main content
Click here to Skip to main content

Simple User Account Login

, 23 Jun 2002
Rate this:
Please Sign up or sign in to vote.
Demonstrates maintaining user account information, managing session state, Access database I/O, cookies, and some other basic features.

Sample Image - UserAccountLogin.jpg

Introduction

This is a simple demonstration of managing user account information on a server using ASP.NET. I decided that this might be a good way to get my feet wet in the whole ASP.NET environment, and the trials that I went through to get this far, might be of interest (and amusement!) to everyone else.

I am very much indebted to the numerous people on CP, who have helped answer some of my very basic questions. You all know who you are, and I thank you very much for your help.

Features

This project demonstrates the use of:

  1. Managing username, password, and configuration options in an MS Access database;
  2. Using HttpResponse.Cookies and HttpRequest.Cookies to remember the user's login name;
  3. Use of HttpSessionState to retain the user ID between web pages
  4. Some simple JavaScript to set the focus of controls on the web pages

The Journey into ASP.NET land

While embarking on this journey, I encountered a variety of "interesting" problems to solve. What follows are my notes regarding the things I learned.

HTML Controls

I wanted to use the HTML password control for passwords, since it displays "dots" for the password text. I couldn't find any web form control that did this. I'm used to the MFC edit box which has a password style. It doesn't seem that the web form edit control has this capability. I could be wrong! In any case, using HTML controls is interesting because to do anything useful with the control in the C# text, you have to convert it into a "server control", which is accomplished quite easily by right clicking on the HTML control and selecting "run as server control". Of course, it took about an hour to figure this out!

Tab order

After I set up my first login screen, I noticed the tab order was wrong. So, silly me, I went looking around the IDE for a "tab order" wizard or menu command like the one for MFC. I couldn't find it! So, instead, I moved the controls around directly in the HTML. That was fairly straight forward. Later on, I discovered the TabIndex property for control. But, since I had my controls all ordered correctly in the HTML by then, I never played with the TabIndex. Personally, I'd rather get them ordered right in the HTML.

Setting the Control ID

It's most helpful if you set the ID's of the web form control first, before creating event handlers. Otherwise, you'll end up with some non-descript name and you'll have to edit the box titled "Web Form Designer generated code" to change the names of the event handlers, etc. Not too painful, but doing it right the first time is very helpful.

Centered Labels

I had an interesting time of getting the "Welcome to my web site" text centered to the size of the panel. I couldn't find a way to center justify the web form label control, so I created an HTML label, set it as "Run As Server Control", then changed the style, etc. Is there a better way?

An annoying thing

The thing that's annoying about these HTML controls is that the method for setting text is different. For example, label text has to be set with the InnerText method, while edit box text is set with the Value method. The inconsistency makes life for beginners harder.

Databases and folder permissions

I pulled my hair out for about a day trying to figure out why I could query the database, but I couldn't update it. A friendly Code Project member replied to my message and pointed out that I needed to put the database into a separate folder that had read/write permission (among other things, so that the .LDB file could be created). I had been playing with permissions in the IIS to no avail. Doing this made everything work, except that originally, my password field was called PASSWORD, which worked fine in queries but not updates.

State, Persistence, and Server vs. Client

I must say, this whole web form stuff being stateless is quite an interesting thing to deal with. You really have to change the style in which you program, and therefore, think, about persistence, etc. Also, I'm learning that I have to segregate my thinking into server vs. client side functionality. So, for example, I was trying to figure out how to set the focus to the user name edit control using a server side method. Posing this question on CP provided me with the answer that, this is a client side thing to do. A code example was kindly provided.

As a veteran MFC/C++ programmer, even having segregated client vs. server database functionality, I find it very hard to create a mental image of what happens on the server and what happens on the client. I think this confusion is aided by the fact that ASP.NET makes this line fuzzier, with event handlers, etc.

Conclusion

I'm not going to do any code snippets here (unless requested). You can peruse the code yourself by downloading the project. It's quite straightforward. All of the code is more or less copied out of the MSDN help and the excellent .NET Framework Essentials from O'Reilly Press, and of course from numerous posts on CP. I've just glued it all together to make a simple demonstration and added some prototypes of classes that might be useful to me later on.

If anyone is interested in some controversial stuff, you can read my comments in the code about how I implemented the database interface. Don't look for encryption on the passwords or a lot of other bells and whistles. This is intended to be a demonstration program only, something of a test-bed as I get by ASP.NET, feet wet.

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

Share

About the Author

Marc Clifton

United States United States
Marc is the creator of two open source projects, MyXaml, a declarative (XML) instantiation engine and the Advanced Unit Testing framework, and Interacx, a commercial n-tier RAD application suite.  Visit his website, www.marcclifton.com, where you will find many of his articles and his blog.
 
Marc lives in Philmont, NY.

Comments and Discussions

 
QuestionHai getting parsing error.. <%@ Application Codebehind="Global.asax.cs" Inherits="Account.Global" %> PinmemberSoorajth9-Feb-09 19:02 
GeneralRegistration and Log In Pinmembervbconcepts22-Apr-08 7:41 
GeneralRe: Registration and Log In Pinmembermauji11-Jul-09 22:38 
GeneralLogin problem Pinmemberkidus12-Oct-07 9:16 
GeneralLogin.html Pinmemberkaushik.mota17-Dec-05 8:56 
GeneralI'v got error plase Help!!! PinmemberAngleBkk7-Jul-05 6:17 
GeneralRe: I'v got error plase Help!!! Pinmemberlauralucas29-Jun-06 11:18 
GeneralRe: I'v got error plase Help!!! Pinmembercrop47-Sep-06 6:48 
GeneralGetting a Parse Error Pinmemberwebdinamico23-Jan-05 10:15 
GeneralRe: Getting a Parse Error Pinmemberkerberos_prozac30-Mar-05 14:45 
Generalbetter way Pinmemberidishkov14-Apr-04 23:11 
Generalaj aj aj poor coder Pinsussidishkov214-Apr-04 23:04 
Generalhorrible Pinmemberzoelopital2-Oct-03 6:03 
GeneralRe: horrible PineditorMarc Clifton2-Oct-03 6:20 
GeneralRe: horrible PinsussOggmanski2-Oct-03 10:08 
GeneralRe: horrible PineditorMarc Clifton2-Oct-03 10:17 
GeneralRe: horrible PinmemberJoel Koblich21-May-05 18:38 
GeneralSession state Pinmemberjmathew5-Jul-03 12:34 
GeneralBasics, very basics Pinmemberjgmata23-Jun-03 7:30 
GeneralUsing information Pinmemberkellyho6714-Jan-03 12:54 
GeneralTabIndex property doesn't work. PinmemberPhillip H. Blanton17-Dec-02 10:33 
GeneralGood article PinmemberLaMagra27-Aug-02 0:16 
General"Operation must use an updateable query." PinmemberSasha Djurovic3-Jul-02 13:34 
GeneralRe: "Operation must use an updateable query." PinmemberSasha Djurovic3-Jul-02 14:13 
GeneralRe: "Operation must use an updateable query." PinsussAnonymous28-Jul-02 19:58 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 24 Jun 2002
Article Copyright 2002 by Marc Clifton
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid