i think its because of this :<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.Data.SQLClient" %
<Script Runat="Server">
Dim connstr as string = "Server=-;UID=-;PWD=-;Database=-"
Dim return_page as string = "http://natwww01dev/endoscopy/accounttransfers/approval.aspx"
Dim back_page as string = "http://natwww01dev/endoscopy/samplecode/bscireal.aspx"
Dim refresh_page as string = "http://natwww01dev/endoscopy/login.aspx"Sub Page_Load(sender As Object, e As EventArgs)
Dim sql as string
sql = "SELECT Region From Regions"FillDropDownList(sql,ddlusername)
End Sub
Sub button_Click (s As Object, e as EventArgs)
If IsValid Then
Dim IntUserID as String
IntUserID = DBAuthenticate(ddlusername.selecteditem.text, txtpassword.text)
Select Case IntUserID
Case -1
LblMessage.text = "Non existent user"
Case -2
LblMessage.text = "Invalid Password"
Case Else
Session("Regionid") = IntUserID
Session("RegionName") = ddlusername.selecteditem.text
FormsAuthentication.redirectfromloginpage(IntUserID, false)
response.redirect(return_page)
End Select
end If
End SubSub button_Click2 (s As Object, e as EventArgs)
response.redirect(back_page)End Sub
Function DBAuthenticate (strUsername As String, strPassword As String) As String
Dim conMyData As SqlConnection
Dim cmdSelect As SqlCommand
Dim ParmReturnValue As SqlParameterconMyData = New SqlConnection("Server=-;UID=-;PWD=-;Database=-")
cmdSelect = New SqlCommand ("DbAuthenticate", conMyData)
cmdSelect.CommandType = CommandType.StoredProcedure
cmdSelect.Parameters.Add( "@dotnet.itags.org.retstring", SqlDBType.varchar, 4).Direction = ParameterDirection.OutputcmdSelect.Parameters.add("@dotnet.itags.org.login", strusername)
cmdSelect.Parameters.add("@dotnet.itags.org.pw", strpassword)conMyData.Open()
cmdSelect.ExecuteNonQuery()
conMyData.Close()
Dim result as string = CStr(cmdSelect.Parameters("@dotnet.itags.org.retstring").value)Return result
End Function
Sub FillDropDownList(sql as string, ddl as DropDownList)' Create Connection Object, Command Object, Connect to the database
Dim conn as New SQLConnection(connstr)
Dim cmd as New SQLCommand(sql,conn)
conn.open()' Execute the SQL, Bind the results to the Dropdown List Control
ddl.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
ddl.DataBind()End Sub
</script>
<html>
<head>
<title>Region Manager Login </title
</head>
<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<form runat="server" name="login" action="approval4.aspx" method="post">
<table height="100%" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr bgcolor="#000000">
<td valign="top" align="left">
</td>
</tr>
<tr>
<td width="100%" background="gor_white.bmp">
<img height="1" src="http://pics.10026.com/?src=images/gor_white.gif" width="20" border="NONE" /></td>
</tr>
<tr bgcolor="#002041">
<td valign="top" align="left" width="100%" height="77">
<img height="77" src="http://pics.10026.com/?src=images/header.gif" width="960" /></td>
</tr>
<tr>
<td width="100%" background="gor_white.bmp">
<img height="1" src="http://pics.10026.com/?src=images/gor_white.bmp" width="20" border="NONE" /></td>
</tr>
<tr bgcolor="#36647e">
<td valign="top" align="left">
</td>
</tr>
<tr>
<td valign="center" align="middle" height="98%"> <br /> <br />
<table bordercolor="#5e768e" cellspacing="0" cellpadding="5" width="770" bgcolor="#b6cce4" border="1">
<tbody>
<tr><td>
<table bordercolor="#5e768e" cellspacing="0" cellpadding="5" width="770" border="0">
<tbody>
<tr><td align="center" valign="middle"><asp:Label id="lbl_error" runat="server"width="500px" font-names="Verdana" font-size="X-Small" font-bold="True" forecolor="#002041" text="Welcome to
the Login page. Please enter your region name and password."> </asp:Label></center></td></tr>
<td align="center" valign="top">
<table bordercolor="#5e768e" bgcolor="#36647e" cellspacing="0" cellpadding="0" width="300" bgcolor="#b6cce4"border="1"> <tbody><tr><td>
<table bordercolor="#5e768e" bgcolor="#36647e" cellspacing="0" cellpadding="5" width="300" border="0"><tbody
<tr><td valign="middle" width="200"><font face="Verdana" size="2" color="#FFFFFF">Region Name:</font></td><td align="center" valign="middle" width="100"><asp:DropDownList Id="ddlusername"
runat="server" DataValueField="Region" DataTextField="Region"
width="100"></asp:DropDownList><asp:requiredfieldvalidator ControltoValidate="ddlusername" Text="Required!"
Runat="server" />
</td></tr>
<tr><td valign="middle" width="200"><font face="Verdana" size="2" color="#FFFFFF">Password:</font></td><td align="center" valign="middle" width="100"><asp:textbox Id ="txtPassword" Runat="server"
TextMode="Password" width="100" />
<asp:requiredfieldvalidator ControltoValidate="txtPassword" Text="Required!" Runat="server" />
</td></tr><tr><td align="center" valign="middle" colspan="2"><asp:Button id="login" onclick="button_Click"runat="server" Text="Login!"></asp:Button> <asp:Button id="back" onclick="button_Click2"
runat="server" Text="Back"></asp:Button></td></tr><tr><td align="center" valign="middle"
colspan="2"><asp:label id="lblmessage" runat="server" font-names="Verdana" font-size="X-Small"
font-bold="True" forecolor="#FFFFFF"></asp:label>
</form>
FormsAuthentication.redirectfromloginpage(IntUserID, false)
make it true. i thnk you should persis the cookie.
also your function is set to return a string and you are checking for -1 and -2..etc. that cuold be one other thing you can check. make it integer and return 0,1,2 etc.
hth
I tried changing the formsauthentication to true, and that did not work. What do i need to do to persist the cookie? Also, I has to be set up as a string, because it returns user ID's and there are cases where the userID's contain letters. My web config file is set up correctly, and my stored procedure seems fine, so there MUST be something I am overlooking in the code. Here's my new code. When i select a name from the drop down and type in te wrong password, i get 'invalid password'. However, when I type in the right password, nothing happens. I had it working correctly with a text box, but now I changed parts of my web.config file and the textbox mode wont work either. What could be going on here? :
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SQLClient" %
<Script Runat="Server">
Dim connstr as string = "Server=*8;UID=*;PWD=*;Database=*"
Dim return_page as string = "http://natwww01dev/endoscopy/accounttransfers/approval.aspx"
Dim back_page as string = "http://natwww01dev/endoscopy/samplecode/bscireal.aspx"
Dim refresh_page as string = "http://natwww01dev/endoscopy/login.aspx"Sub Page_Load(sender As Object, e As EventArgs)
Dim sql as string
sql = "SELECT Region From Regions"FillDropDownList(sql,ddlusername)
End Sub
Sub button_Click (s As Object, e as EventArgs)
If IsValid Then
Dim IntUserID as String
IntUserID = DBAuthenticate(ddlusername.selecteditem.text, txtpassword.text)
Select Case IntUserID
Case -1
LblMessage.text = "Non existent user"
Case -2
LblMessage.text = "Invalid Password"
Case Else
Session("Regionid") = IntUserID
Session("RegionName") = ddlusername.selecteditem.text
FormsAuthentication.redirectfromloginpage(IntUserID, true)
End Select
end If
End SubSub button_Click2 (s As Object, e as EventArgs)
response.redirect(back_page)End Sub
Function DBAuthenticate (strUsername As String, strPassword As String) As String
Dim conMyData As SqlConnection
Dim cmdSelect As SqlCommand
Dim ParmReturnValue As SqlParameterconMyData = New SqlConnection("Server=*;UID=E*;PWD=*;Database=*")
cmdSelect = New SqlCommand ("DbAuthenticate", conMyData)
cmdSelect.CommandType = CommandType.StoredProcedure
cmdSelect.Parameters.Add( "@.retstring", SqlDBType.varchar, 4).Direction = ParameterDirection.OutputcmdSelect.Parameters.add("@.login", strusername)
cmdSelect.Parameters.add("@.pw", strpassword)conMyData.Open()
cmdSelect.ExecuteNonQuery()
conMyData.Close()
Dim result as string = CStr(cmdSelect.Parameters("@.retstring").value)Return result
End Function
Sub FillDropDownList(sql as string, ddl as DropDownList)' Create Connection Object, Command Object, Connect to the database
Dim conn as New SQLConnection(connstr)
Dim cmd as New SQLCommand(sql,conn)
conn.open()' Execute the SQL, Bind the results to the Dropdown List Control
ddl.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
ddl.DataBind()End Sub
</script>
<html>
<head>
<title>Region Manager Login </title
</head>
<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<form runat="server" name="login" method="post">
<table height="100%" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr bgcolor="#000000">
<td valign="top" align="left">
</td>
</tr>
<tr>
<td width="100%" background="gor_white.bmp">
<img height="1" src="http://pics.10026.com/?src=images/gor_white.gif" width="20" border="NONE" /></td>
</tr>
<tr bgcolor="#002041">
<td valign="top" align="left" width="100%" height="77">
<img height="77" src="http://pics.10026.com/?src=images/header.gif" width="960" /></td>
</tr>
<tr>
<td width="100%" background="gor_white.bmp">
<img height="1" src="http://pics.10026.com/?src=images/gor_white.bmp" width="20" border="NONE" /></td>
</tr>
<tr bgcolor="#36647e">
<td valign="top" align="left">
</td>
</tr>
<tr>
<td valign="center" align="middle" height="98%"> <br /> <br />
<table bordercolor="#5e768e" cellspacing="0" cellpadding="5" width="770" bgcolor="#b6cce4" border="1">
<tbody>
<tr><td>
<table bordercolor="#5e768e" cellspacing="0" cellpadding="5" width="770" border="0">
<tbody>
<tr><td align="center" valign="middle"><asp:Label id="lbl_error" runat="server" width="500px" font-names="Verdana" font-size="X-Small" font-bold="True" forecolor="#002041" text="Welcome to the Login page. Please enter your region name and password."> </asp:Label></center></td></tr>
<td align="center" valign="top">
<table bordercolor="#5e768e" bgcolor="#36647e" cellspacing="0" cellpadding="0" width="300" bgcolor="#b6cce4" border="1"> <tbody><tr><td>
<table bordercolor="#5e768e" bgcolor="#36647e" cellspacing="0" cellpadding="5" width="300" border="0"><tbody
<tr><td valign="middle" width="200"><font face="Verdana" size="2" color="#FFFFFF">Region Name:</font></td><td align="center" valign="middle" width="100"><asp:DropDownList Id="ddlusername" runat="server" DataValueField="Region" DataTextField="Region" width="100"></asp:DropDownList><asp:requiredfieldvalidator ControltoValidate="ddlusername" Text="Required!" Runat="server" />
</td></tr>
<tr><td valign="middle" width="200"><font face="Verdana" size="2" color="#FFFFFF">Password:</font></td><td align="center" valign="middle" width="100"><asp:textbox Id ="txtPassword" Runat="server" TextMode="Password" width="100" />
<asp:requiredfieldvalidator ControltoValidate="txtPassword" Text="Required!" Runat="server" />
</td></tr><tr><td align="center" valign="middle" colspan="2"><asp:Button id="login" onclick="button_Click" runat="server" Text="Login!"></asp:Button> <asp:Button id="back" onclick="button_Click2" runat="server" Text="Back"></asp:Button></td></tr><tr><td align="center" valign="middle" colspan="2"><asp:label id="lblmessage" runat="server" font-names="Verdana" font-size="X-Small" font-bold="True" forecolor="#FFFFFF"></asp:label>
</form>
Set the AutoPostBack true for the ddl and also handle PostBack
What do you mean handle postback?
Just a comment:
modify the page_load to this:
Sub Page_Load(sender As Object, e As EventArgs)Dim sql as string
if(Not Page.IsPostack) Then
sql = "SELECT Region From Regions"FillDropDownList(sql,ddlusername)
End IfEnd Sub
Dear Mat,
I have already provided the solution for your requirement.
Check thisArticle
If you have problems, write back.
Thanks.
I don't believe your solution works for my problem.
I am completely stumped by this problem i am having. I have configured my web.config file and stored proecedures properly, so I believe there is something wrong with my code. Why am i not able to Login? When i select a username from the list and type in the wrong password, I get the 'invalid password' written in my label. However, when i type in the right password, the page simply seems to reload or postback to itself (If i test with the wrong password first and then try with the correct password, the 'invalid password' remains in the label). I would apprecaite any help in determining what's wrong here! How do i fix this so when the correct user name is entered, I am brought to my next page, which i want to be approval.aspx?
I think this is ambiguous:
FormsAuthentication.redirectfromloginpage(IntUserID, false)
response.redirect(return_page)
RedirectFromLoginPage will redirect to a url in the querystring, if present (ReturnURL), if not to Default.aspx (if not present then it may cause problems... I don't know).
Anyway, response.Redirect WILL NOT be executed, at least that is what is supposed to happen.
If you want to authenticate the user AND redirect to any page you want then do this:
System.Web.Security.FormsAuthentication.SetAuthCookie(IntUserID,false)
response.redirect(return_page)
I hope this helps,
Eh. That doesn't seem to help. I'm completely stumped!
When i close my browser, open a new one, and type in the url for the login page, I am brought to login.aspx, which should obviously happen. When i select a username from the list and type in the right password, the page disappears for a half second, then reappears with nothing filled in the password but the same region selected from the username drop down. Someone had me autopostback the ddl, but that does nothing...
What is this telling me, considering the select case in my event handler seems to read the -2 value that gives the 'invalid password' text in my label. What is the problem?
In your code you have this:
Dim IntUserID as String
IntUserID = DBAuthenticate(ddlusername.selecteditem.text, txtpassword.text)
Why is it a String when in your select you are evaluating it as an integer?
Because my stored procedure is returning the userID if the username and password are correct, and in some cases, the userID can contain letters, like 'zzx'. Is this what you mean, just by seeing case -1 and case -2??
I have tried to debug by placing response.writes all throughout the function dbauthenticate, and tried to write "hello" on lblmessage before the select... but nothing with showing on the page.. Here is my updated code. I am totally confused as to why it returns the -2 case and displays 'invalid password' but does nothing for my case else.
Sub button_Click (s As Object, e as EventArgs)
If IsValid Then
Dim IntUserID as String
IntUserID = DBAuthenticate(ddlusername.selecteditem.text, txtpassword.text)
LblMessage.text = "PLEASE SHOW UP"
Select Case IntUserID
Case -1
LblMessage.text = "Non existent user"
Case -2
LblMessage.text = "Invalid Password"
Case Else
Session("Regionid") = IntUserID
Session("RegionName") = ddlusername.selecteditem.text
FormsAuthentication.redirectfromloginpage(IntUserID, false)
End Select
end If
End SubSub button_Click2 (s As Object, e as EventArgs)
response.redirect(back_page)End Sub
Function DBAuthenticate (strUsername As String, strPassword As String) As String
Dim conMyData As SqlConnection
Dim cmdSelect As SqlCommand
Dim ParmReturnValue As SqlParameterconMyData = New SqlConnection("Server=localhost;UID=;PWD=;Database=")
cmdSelect = New SqlCommand ("DbAuthenticate2", conMyData)
cmdSelect.CommandType = CommandType.StoredProcedure
cmdSelect.Parameters.Add( "@.retstring", SqlDBType.varchar, 4).Direction = ParameterDirection.OutputcmdSelect.Parameters.add("@.login", strusername)
cmdSelect.Parameters.add("@.pw", strpassword)conMyData.Open()
cmdSelect.ExecuteNonQuery()
conMyData.Close()
Dim result as string = CStr(cmdSelect.Parameters("@.retstring").value)Return result
response.write(result)
End Function
0 comments:
Post a Comment