PDA

Click to See Complete Forum and Search --> : Database webform authentication


venerable bede
Nov 19th, 2002, 12:42 PM
I am desperate to find an example of webforms authentication using Vb.net/asp.net and SQL Server.

The examples I have found so far are all in C# require xml or are confusing.

Can anyone help?

I used to do this type of thing in my sleep in good old asp.

Thanks in advance

KMG
Nov 21st, 2002, 11:06 AM
Hello,

I had the same problem as you, I found this article to be very helpful, and was able to get it to work just fine.

http://support.microsoft.com/default.aspx?scid=kb;EN-US;308157

Kenny

Wokawidget
Jun 15th, 2004, 04:13 AM
This is what I sue and it seems to work.
I am not to hot at ASP.NET yet, but it seems straight forward.

In your Web.Config file you need:

<authentication mode="Forms">
<forms
name=".ASPXAUTH"
loginUrl="login.aspx"
protection="All"
slidingExpiration="true"
timeout = "10"
/>
</authentication>
<authorization>
<deny users="?" />
</authorization>

I have a login page, which I am assuming you have to.
The code in my "login" button is:

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim objTicket As FormsAuthenticationTicket
Dim objCookie As HttpCookie
Dim strReturnURL As String
If IsValid Then
If txtUsername.Text = "wokawidget" And txtPassword.Text = "woof" Then
objTicket = New FormsAuthenticationTicket(txtUsername.Text, False, 5)
objCookie = New HttpCookie(".ASPXAUTH")
objCookie.Value = FormsAuthentication.Encrypt(objTicket)
Response.Cookies.Add(objCookie)
strReturnURL = Request.Params("ReturnURL")
If strReturnURL Is Nothing Then
Response.Redirect("Main.aspx")
Else
Response.Redirect(strReturnURL)
End If
Else
lblMessage.Text = "Incorect username/password"
End If
Else
lblMessage.Text = "Incorect username/password"

End If
End Sub

You need to import System.Web.Security for this.
I am currently learning more about this subject, and am just in the process of having users in a DB table.

Both the Login page, and the web config file, have references to ".ASPXAUTH". These MUST be the same name! It could be ".WOOF" for all you care, but so long as they are the same it will work.

Woka

venerable bede
Jun 15th, 2004, 05:42 AM
I asked this question 2 years ago.

Such speed!!

Wokawidget
Jun 15th, 2004, 05:45 AM
I try my best ;)

Hahaha...ooops. I did a search as I was looking for some extra info on it, and I saw this thread. Didn't think to look at the date :(
Hahaha. I have only been doing ASP.NET for 2 days now, am a complete beginner.

Do you know much about form authentication?

Woof