Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 30th, 2006, 10:44 AM
Registered User
 
Join Date: Jun 2006
Location: , Idaho, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Connecting the Login Control to a Custom Database?

Here's my problem:

I have a database with a single table that's loaded with information, and each row represents a single person that database. I have several different pages in my site already that basically display the information about each person in a variety of ways (A manager/employee hierarchy, search function, etc).

However, where I'm stuck is at the capability of allowing these several different people/users to log in and change their own information within the database. I've added a username and password column and given each person values for them, but I can't figure out how to connect the login control to them.

If I use the default control, it wants me to either manually create all of the users in roles and groups (Which won't work because I need to be able to get Joe Manager or whoever the capability of adding whole new people to the database), or use Windows Authentication (Which I can't do because it's over the internet).

I've looked up some stuff on the internet and have tried changing my web.config file, but if that is the answer, I don't know how to direct it to the username/password fields in my database. Can I even go through the built-in login control? Do I have to change the web.config file? Am I making this way more difficult than it needs to be? ^_~ It just sounds like it'd be a no brainer to be able to connect a login control to a couple fields in a database... >_>

(I'm not entirely sure what kind of database I'm using... Just whatever the default is in Visual Studio 2005, so I'd imagine MSSQL. Also, I'm using C#, so that's preferred, but I found a nifty VB -> C# converter thing that I can use if I have to.)

Thanks!
Reply With Quote
  #2 (permalink)  
Old June 30th, 2006, 04:07 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

There are a few ways to fix this problem. If all you're interested in is reusing the Login control to validate a user against a custom database schema, you could hook into the Authenticate event. Inside that event, you can access your own database and then set the Authenticated property based on the outcome of the database access.

However, if you want to use all of the Membership features that ASP.NET 2 provides, you could write your own provider that targets your own database. This article may server as a nice starting point: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=380

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
  #3 (permalink)  
Old July 5th, 2006, 03:06 PM
Registered User
 
Join Date: Jun 2006
Location: , Idaho, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmrm...

While that does seem like it'd work out just fine, it seems too complex for what I'm currently trying to do. I only need this for a like a demo/presentation, so I don't think it needs to be too tough.

I've looked at just making my own login using textbox and button controls, and it seems like all I'd have to do would be pass information from one page to another, probably using Session State.

Problem is, I'm not sure how I can transfer whatever the user put into the login boxes to the next page (Which is why I think I need Session State). How could I use that?

Reply With Quote
  #4 (permalink)  
Old July 5th, 2006, 03:31 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

It doesn't have to be so hard.

Add code like this in the Authenticate event:

Protected Sub Login1_Authenticate(ByVal sender As Object, _
     ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) _
     Handles Login1.Authenticate
  e.Authenticated = True
  FormsAuthentication.RedirectFromLoginPage(Login1.U serName, True)
End Sub

Instead of setting Authenticated to True, call your database and pass in the username and password.

After that, the user will be seen as authenticated.

Search the MSDN site for FormsAuthentication.RedirectFromLoginPage and for the web.config settings for the Authentication and Authorization nodes.

In short, you need something like this:

<authentication mode="Forms">
  <forms loginUrl="Login.aspx" defaultUrl="Default.aspx" />
</authentication>
<authorization>
  <deny users="?"></deny>
</authorization>

This blocks access for all users, unless they are authenticated.

IMO, this is a much cleaner solution than rolling your own security stuff.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Server Control....Custom Property Editor ZArrinPour ASP.NET 1.0 and 1.1 Basics 1 June 15th, 2010 11:30 AM
Web Service, Custom Control, Custom Return Type robzyc ASP.NET 2.0 Basics 6 June 10th, 2008 08:03 AM
custom control inside custom control issues StevesonD ASP.NET 2.0 Professional 1 February 19th, 2008 06:54 PM
Custom Membership Provider and Login Control sonishpaul ASP.NET 2.0 Professional 2 December 14th, 2007 02:36 PM
Connecting login to more database information donthomaso Dreamweaver (all versions) 3 May 9th, 2005 03:28 PM



All times are GMT -4. The time now is 06:03 AM.


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