G
Guest
Hi there,
My asp.net site is located in http://localhost/websecurity/
In my LoginPage.aspx page code behind has these code ....
-----------------------------------------------------------------
Imports System.Data.SqlClient
Imports System.Web.Security
Imports System.Text
Imports System
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If CustomAuthenticate(UserName.Text, Password.Text) Then
Dim url As String = FormsAuthentication.GetRedirectUrl(UserName.Text,
Persistent.Checked)
FormsAuthentication.SetAuthCookie(UserName.Text, Persistent.Checked)
If Persistent.Checked Then
Dim cookie As HttpCookie =
Response.Cookies(FormsAuthentication.FormsCookieName)
Dim myTimeStr As String = DateTime.Now
cookie.Expires = myTimeStr
Response.Redirect(url)
Else
Output.Text = "Invalid login"
End If
End If
End Sub
Function CustomAuthenticate(ByVal username As String, ByVal password As
String) As Boolean
Dim connection As New
SqlConnection("server=localhost;database=weblogin;uid=sa;pwd=")
Try
connection.Open()
Dim builder As New StringBuilder
builder.Append("select count (*) from users " + "where username = '")
builder.Append(username)
builder.Append("' and cast (rtrim (password) as " + "varbinary) = cast ('")
builder.Append(password)
builder.Append("' as varbinary)")
Dim command As New SqlCommand(builder.ToString(), connection)
Dim count As Integer = Fix(command.ExecuteScalar())
Return count > 0
Catch
Return False
Finally
connection.Close()
End Try
End Function 'CustomAuthenticate
-----------------------------------------------------------------
My default web.config has this value only
<configuration>
<system.web>
<authentication mode="Forms">
<forms loginUrl="LoginPage.aspx" />
</authentication>
</system.web>
</configuration>
-----------------------------------------------------------------
I also have folder name Secret and contains protectedPage.aspx and has this
code only
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Response.Write(Context.User.Identity.Name + ": ")
End Sub
-----------------------------------------------------------------
Also I have web.config under Secret folder and its code is:
<configuration>
<system.web>
<authorization>
<allow roles="Manager" />
<deny users="*" />
</authorization>
</system.web>
</configuration>
-----------------------------------------------------------------
I set the SQL SERVER and I created a table with
UserName
Password and Role columns.
One of the user name is John and his password is redrover and his role is
Manager.
But when I enter the information in LoginPage.aspx nothing happends. When I
try to debug I get and error:
"Error while trying to run project, Unable to start debuging on the server.
This project is not configured to be debugged."
The idea came from
http://msdn.microsoft.com/msdnmag/issues/02/05/ASPSec2/default.aspx
and it was writen in C Sharp using C Sharp script. I translate into vb
code-behind page and it seems cannot work.
Can anyone have any idea what should I do?
Thank you.
Rgds,
GC
My asp.net site is located in http://localhost/websecurity/
In my LoginPage.aspx page code behind has these code ....
-----------------------------------------------------------------
Imports System.Data.SqlClient
Imports System.Web.Security
Imports System.Text
Imports System
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If CustomAuthenticate(UserName.Text, Password.Text) Then
Dim url As String = FormsAuthentication.GetRedirectUrl(UserName.Text,
Persistent.Checked)
FormsAuthentication.SetAuthCookie(UserName.Text, Persistent.Checked)
If Persistent.Checked Then
Dim cookie As HttpCookie =
Response.Cookies(FormsAuthentication.FormsCookieName)
Dim myTimeStr As String = DateTime.Now
cookie.Expires = myTimeStr
Response.Redirect(url)
Else
Output.Text = "Invalid login"
End If
End If
End Sub
Function CustomAuthenticate(ByVal username As String, ByVal password As
String) As Boolean
Dim connection As New
SqlConnection("server=localhost;database=weblogin;uid=sa;pwd=")
Try
connection.Open()
Dim builder As New StringBuilder
builder.Append("select count (*) from users " + "where username = '")
builder.Append(username)
builder.Append("' and cast (rtrim (password) as " + "varbinary) = cast ('")
builder.Append(password)
builder.Append("' as varbinary)")
Dim command As New SqlCommand(builder.ToString(), connection)
Dim count As Integer = Fix(command.ExecuteScalar())
Return count > 0
Catch
Return False
Finally
connection.Close()
End Try
End Function 'CustomAuthenticate
-----------------------------------------------------------------
My default web.config has this value only
<configuration>
<system.web>
<authentication mode="Forms">
<forms loginUrl="LoginPage.aspx" />
</authentication>
</system.web>
</configuration>
-----------------------------------------------------------------
I also have folder name Secret and contains protectedPage.aspx and has this
code only
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Response.Write(Context.User.Identity.Name + ": ")
End Sub
-----------------------------------------------------------------
Also I have web.config under Secret folder and its code is:
<configuration>
<system.web>
<authorization>
<allow roles="Manager" />
<deny users="*" />
</authorization>
</system.web>
</configuration>
-----------------------------------------------------------------
I set the SQL SERVER and I created a table with
UserName
Password and Role columns.
One of the user name is John and his password is redrover and his role is
Manager.
But when I enter the information in LoginPage.aspx nothing happends. When I
try to debug I get and error:
"Error while trying to run project, Unable to start debuging on the server.
This project is not configured to be debugged."
The idea came from
http://msdn.microsoft.com/msdnmag/issues/02/05/ASPSec2/default.aspx
and it was writen in C Sharp using C Sharp script. I translate into vb
code-behind page and it seems cannot work.
Can anyone have any idea what should I do?
Thank you.
Rgds,
GC