Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
when i copy the any url of my application its running without login how to control it.
Posted

1 solution

it is depend on how you handle the authentication in your web site.
What you can do is check for user authenticated or not in your page load method and redirect to login page if not authenticated.

for example if you using form authentication, you can do as below in page load method

C#
if(!this.Context.User.Identity.IsAuthenticated)
{
  Respose.Redirect("~/LoginPage.aspx");
}
 
Share this answer
 
v3
Comments
Debabrata_Das 15-Jun-14 10:04am    
my 5!
DamithSL 15-Jun-14 10:08am    
Thanks DD
vanarajranjit 15-Jun-14 10:59am    
Actually this is my code how to check the user authenticated or not
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Try
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("SqlDbConnection").ToString())
Dim command As New SqlCommand("cyl_user_login", con)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add("@emp_code", SqlDbType.VarChar).Value = txtusername.Text.Trim()
command.Parameters.Add("@user_password", SqlDbType.VarChar).Value = txtpassword.Text.Trim()
con.Open()
command.ExecuteNonQuery()
Session("@emp_code") = txtusername.Text
'Session("user_password") = txtpassword
Response.Redirect("Home.aspx")
con.Close()
Catch ex As Exception
'Label1.Text = "Wrong Password"
'Console.WriteLine("SQL Error" & ex.Message.ToString())
Label1.Text = ex.Message.ToString()
'ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "alertMessage", "alert('" & ex.Message.ToString() & "')", True)
End Try

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = ""
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

txtusername.Text = ""
txtpassword.Text = ""
End Sub
End Class
Bernhard Hiller 16-Jun-14 2:43am    
Is that step really so complicated? Did you just copy the code without understanding it?
Look at
Session("@emp_code")
if that does not exist or is empty, then send the user back to login.
vanarajranjit 17-Jun-14 23:39pm    
What you saying I am. Not understandable please find the solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900