473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Forms Authentication Problem...

Can someone please tell me why I keep being redirected back to the login page
even though I have logged in with the correct cridentials!!!

I have used this code before on another site and it works fine but when I
copied it across to the new site it stops working! All the variables are
passed when I do a debug but it just returns me to the login page again and
again!

Please help! It's driving me nuts!

Thanks!!!

<<CODE>>>

If Page.IsValid Then
'Connect to Database for User Validation
If DBConnection(txtUserName.Text, txtPassword.Text) Then
FormsAuthentication.RedirectFromLoginPage(txtUserN ame.Text,
Remember.Checked)
Else
' Credentials are Invalid
lblMessage.Text = "Invalid Login!"
End If

End If
End Sub
Function DBConnection(ByVal txtUserName As String, ByVal txtPassword As
String) As Boolean
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim cmd As New SqlCommand("ValidateUser", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Dim objParam1, objParam2 As SqlParameter

objParam1 = cmd.Parameters.Add("@UserName", SqlDbType.Char)
objParam2 = cmd.Parameters.Add("@Password", SqlDbType.Char)

objParam1.Direction = ParameterDirection.Input
objParam2.Direction = ParameterDirection.Input

objParam1.Value = txtUserName
objParam2.Value = txtPassword

Try
If Myconn.State = ConnectionState.Closed Then
Myconn.Open()
End If

Dim objReader As SqlDataReader
objReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

While objReader.Read()
If CStr(objReader.GetValue(0)) <> "1" Then
lblMessage.Text = "Invalid Login!"
Else
objReader.Close()
Return True
End If

End While
Catch ex As Exception
lblMessage.Text = "Error Connecting to Database!"
End Try

End Function

<<<Web.Config>>>

<authentication mode="Forms">
<forms name="NWLogin" loginUrl="Admin/Login.aspx" />
</authentication>
<!-- AUTHORIZATION
This section sets the authorization policies of the application.
You can allow or deny access
to application resources by user or role. Wildcards: "*" mean
everyone, "?" means anonymous
(unauthenticated) users.
-->
<authorization>

<allow roles="Administrator, User" /> <!-- ONLY USERS ALLOWED THAT BELONG
TO THESE GROUPS -->
<deny users="*" /> <!-- Deny all users -->

<!-- <allow users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization>
Nov 19 '05 #1
2 1048
Please forget the last mail!

I managed to figure it out!
Thanks

"Tim::.." wrote:
Can someone please tell me why I keep being redirected back to the login page
even though I have logged in with the correct cridentials!!!

I have used this code before on another site and it works fine but when I
copied it across to the new site it stops working! All the variables are
passed when I do a debug but it just returns me to the login page again and
again!

Please help! It's driving me nuts!

Thanks!!!

<<CODE>>>

If Page.IsValid Then
'Connect to Database for User Validation
If DBConnection(txtUserName.Text, txtPassword.Text) Then
FormsAuthentication.RedirectFromLoginPage(txtUserN ame.Text,
Remember.Checked)
Else
' Credentials are Invalid
lblMessage.Text = "Invalid Login!"
End If

End If
End Sub
Function DBConnection(ByVal txtUserName As String, ByVal txtPassword As
String) As Boolean
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim cmd As New SqlCommand("ValidateUser", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Dim objParam1, objParam2 As SqlParameter

objParam1 = cmd.Parameters.Add("@UserName", SqlDbType.Char)
objParam2 = cmd.Parameters.Add("@Password", SqlDbType.Char)

objParam1.Direction = ParameterDirection.Input
objParam2.Direction = ParameterDirection.Input

objParam1.Value = txtUserName
objParam2.Value = txtPassword

Try
If Myconn.State = ConnectionState.Closed Then
Myconn.Open()
End If

Dim objReader As SqlDataReader
objReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

While objReader.Read()
If CStr(objReader.GetValue(0)) <> "1" Then
lblMessage.Text = "Invalid Login!"
Else
objReader.Close()
Return True
End If

End While
Catch ex As Exception
lblMessage.Text = "Error Connecting to Database!"
End Try

End Function

<<<Web.Config>>>

<authentication mode="Forms">
<forms name="NWLogin" loginUrl="Admin/Login.aspx" />
</authentication>
<!-- AUTHORIZATION
This section sets the authorization policies of the application.
You can allow or deny access
to application resources by user or role. Wildcards: "*" mean
everyone, "?" means anonymous
(unauthenticated) users.
-->
<authorization>

<allow roles="Administrator, User" /> <!-- ONLY USERS ALLOWED THAT BELONG
TO THESE GROUPS -->
<deny users="*" /> <!-- Deny all users -->

<!-- <allow users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization>

Nov 19 '05 #2
So what were you doing wrong?
Patrick:)
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:6F**********************************@microsof t.com...
Please forget the last mail!

I managed to figure it out!
Thanks

"Tim::.." wrote:
Can someone please tell me why I keep being redirected back to the login page even though I have logged in with the correct cridentials!!!

I have used this code before on another site and it works fine but when I copied it across to the new site it stops working! All the variables are
passed when I do a debug but it just returns me to the login page again and again!

Please help! It's driving me nuts!

Thanks!!!

<<CODE>>>

If Page.IsValid Then
'Connect to Database for User Validation
If DBConnection(txtUserName.Text, txtPassword.Text) Then
FormsAuthentication.RedirectFromLoginPage(txtUserN ame.Text, Remember.Checked)
Else
' Credentials are Invalid
lblMessage.Text = "Invalid Login!"
End If

End If
End Sub
Function DBConnection(ByVal txtUserName As String, ByVal txtPassword As String) As Boolean
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim cmd As New SqlCommand("ValidateUser", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Dim objParam1, objParam2 As SqlParameter

objParam1 = cmd.Parameters.Add("@UserName", SqlDbType.Char)
objParam2 = cmd.Parameters.Add("@Password", SqlDbType.Char)

objParam1.Direction = ParameterDirection.Input
objParam2.Direction = ParameterDirection.Input

objParam1.Value = txtUserName
objParam2.Value = txtPassword

Try
If Myconn.State = ConnectionState.Closed Then
Myconn.Open()
End If

Dim objReader As SqlDataReader
objReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While objReader.Read()
If CStr(objReader.GetValue(0)) <> "1" Then
lblMessage.Text = "Invalid Login!"
Else
objReader.Close()
Return True
End If

End While
Catch ex As Exception
lblMessage.Text = "Error Connecting to Database!"
End Try

End Function

<<<Web.Config>>>

<authentication mode="Forms">
<forms name="NWLogin" loginUrl="Admin/Login.aspx" />
</authentication>
<!-- AUTHORIZATION
This section sets the authorization policies of the application. You can allow or deny access
to application resources by user or role. Wildcards: "*" mean
everyone, "?" means anonymous
(unauthenticated) users.
-->
<authorization>

<allow roles="Administrator, User" /> <!-- ONLY USERS ALLOWED THAT BELONG TO THESE GROUPS -->
<deny users="*" /> <!-- Deny all users -->

<!-- <allow users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization>

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
2
by: Senthil | last post by:
1. Created a new C# web application project 2. Change the name of webform1 to login.aspx 3. And in the .cs file change the name of the class to login, and include System.web.security namespace....
4
by: Greg Burns | last post by:
I have built a web app that uses forms authentication. There isn't a "remember me" feature (i.e. the authentication cookie is not permanent). When you close the browser, and open a new one, you...
3
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
9
by: Hermit Dave | last post by:
Hi, I am making a web application (rather two applications) one which is host and used by customers when they are just browsing through products. The second application resides on a secure...
1
by: Rob | last post by:
I have an ASP.NET application that uses forms-based authentication. A user wishes to be able to run multiple sessions of this application simultaneously from the user's client machine. The...
5
by: Gavin Stevens | last post by:
I'm trying to figure out the ASP.NET Forms Auth I have 3 or 4 pages i want to allow anonymous access to.. Then I have 5 or 6 pages I placed in another directory in the webproject. These I want...
7
by: Justin | last post by:
I am trying to password protect a subdirectory using forms authentication. I am using the "Location" tag to specify the directory to be protected. The login.aspx page is in the root directory of...
1
by: n33470 | last post by:
Hi all, We have an asp.net 1.1 app that we're in the process of converting to 2.0. What I'm about to describe runs just great in the 1.1 framework, but does not work in the 2.0 framework. ...
4
by: =?Utf-8?B?R3V1czEyMw==?= | last post by:
Hi, I created a web site on a remote server. To logon the user must enter a user id and password. The site is uses Forms Authentication. The web config file looks as follows: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.