473,657 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(tx tUserName.Text, txtPassword.Tex t) Then
FormsAuthentica tion.RedirectFr omLoginPage(txt UserName.Text,
Remember.Checke d)
Else
' Credentials are Invalid
lblMessage.Text = "Invalid Login!"
End If

End If
End Sub
Function DBConnection(By Val txtUserName As String, ByVal txtPassword As
String) As Boolean
Dim Myconn As New
SqlConnection(C onfigurationSet tings.AppSettin gs("strConn"))
Dim cmd As New SqlCommand("Val idateUser", Myconn)
cmd.CommandType = CommandType.Sto redProcedure

Dim objParam1, objParam2 As SqlParameter

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

objParam1.Direc tion = ParameterDirect ion.Input
objParam2.Direc tion = ParameterDirect ion.Input

objParam1.Value = txtUserName
objParam2.Value = txtPassword

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

Dim objReader As SqlDataReader
objReader = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion)

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>> >

<authenticati on 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
(unauthenticate d) users.
-->
<authorizatio n>

<allow roles="Administ rator, 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 1058
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(tx tUserName.Text, txtPassword.Tex t) Then
FormsAuthentica tion.RedirectFr omLoginPage(txt UserName.Text,
Remember.Checke d)
Else
' Credentials are Invalid
lblMessage.Text = "Invalid Login!"
End If

End If
End Sub
Function DBConnection(By Val txtUserName As String, ByVal txtPassword As
String) As Boolean
Dim Myconn As New
SqlConnection(C onfigurationSet tings.AppSettin gs("strConn"))
Dim cmd As New SqlCommand("Val idateUser", Myconn)
cmd.CommandType = CommandType.Sto redProcedure

Dim objParam1, objParam2 As SqlParameter

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

objParam1.Direc tion = ParameterDirect ion.Input
objParam2.Direc tion = ParameterDirect ion.Input

objParam1.Value = txtUserName
objParam2.Value = txtPassword

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

Dim objReader As SqlDataReader
objReader = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion)

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>> >

<authenticati on 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
(unauthenticate d) users.
-->
<authorizatio n>

<allow roles="Administ rator, 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_hotm ail.com> wrote in message
news:6F******** *************** ***********@mic rosoft.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(tx tUserName.Text, txtPassword.Tex t) Then
FormsAuthentica tion.RedirectFr omLoginPage(txt UserName.Text, Remember.Checke d)
Else
' Credentials are Invalid
lblMessage.Text = "Invalid Login!"
End If

End If
End Sub
Function DBConnection(By Val txtUserName As String, ByVal txtPassword As String) As Boolean
Dim Myconn As New
SqlConnection(C onfigurationSet tings.AppSettin gs("strConn"))
Dim cmd As New SqlCommand("Val idateUser", Myconn)
cmd.CommandType = CommandType.Sto redProcedure

Dim objParam1, objParam2 As SqlParameter

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

objParam1.Direc tion = ParameterDirect ion.Input
objParam2.Direc tion = ParameterDirect ion.Input

objParam1.Value = txtUserName
objParam2.Value = txtPassword

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

Dim objReader As SqlDataReader
objReader = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion)
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>> >

<authenticati on 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
(unauthenticate d) users.
-->
<authorizatio n>

<allow roles="Administ rator, 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
4819
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 Authentication set up and it worked just fine. Then I realized that I needed to have some pages unsecure. I then created 2 directories. One named Secure and the other named Public. I placed my web.config file in my
2
1719
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. Place a textbox and a button in the login.aspx form. 5. Have the following code in the button click event. if (true) { FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false)
4
2736
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 must log in again. This is the behavior I expected. I just discovered that if I have a browser window open (to anything) prior to opening my web app in a new browser window, it appears to share session information. I can then open and close my...
3
4861
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 protected by forms authentication. When I create forms authentication at root level it works but when I move my code up to the subfolder I get this error: Server Error in '/TestProjects/FormsAuthenticationTestingArea' Application.
9
4629
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 server. This is going to hold all account related information for the customers and will also be used for admin The login is implemented using forms authentication and i was just reading up about that... but as everyone already knows.... its all...
1
3493
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 web.config file is configured as such: <authentication mode="Forms"> <forms loginUrl="Login.aspx" protection="All" name="myApplication"/> </authentication>
5
2870
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 to manually authenticate users to provide acess My project has 2 web.config files... the default file <authentication mode="Forms"><forms loginUrl="Login.aspx" protection="All" timeout="30"...
7
2033
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 the app. Here is the web.config: <location path="Admin"> <system.web> <authentication mode="Forms"> <forms name="authAdmin" loginUrl="Login.aspx" protection="All" timeout="30"> <credentials passwordFormat="Clear"> <user name="Admin"...
1
6444
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. This app uses forms authentication and denies all unauthenticated users. There is a location override in the web.config so that we can open up a directory for unauthenticated users to create a login account. There is only 1 web.config in the...
4
424
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: <configuration> <system.web> <customErrors mode="Off"/>
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.