Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
iwant to do authencation for multi user and deny any user to enter to site whithout pass throw log in page
add security to may site and deny any user pass to site pages without pass login page]\
the answe very beutiful and i ahave many ready code


but i want from you code if we but deny user no body can enter i want to create new user

and mke hime enter and the name of user stored in data base

and
iwill but may code


SqlConnection c;
SqlCommand m;
SqlDataReader r;

public void get_con()
{
c = new SqlConnection();
c.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\pard.mdf;Integrated Security=True;User Instance=True";
}

protected void Page_Load(object sender, EventArgs e)
{
get_con();
}


protected void Button1_Click(object sender, EventArgs e)
{


m = new SqlCommand();
c.Open();
m.Connection = c;

m.Parameters.Add("@a", TextBox2name.Text);
m.CommandText = "select [prd] from [user] where nam=@a";


r = m.ExecuteReader();
if (r.HasRows == false)
Response.Write("rrrrr");
if (r.Read())
{
if (r["prd"].ToString() == TextBox1pard.Text.Trim())
{
Response.Redirect("WebForm6.aspx");
}

}
else
{
Response.Write("wrong prd");
}
c.Close();




}
Posted
Updated 29-Jun-11 2:03am
v3

1 solution

Have a look at ASP.Net Authorisation along with .Net forms authentication

http://msdn.microsoft.com/en-us/library/wce3kxhd.aspx[^]

http://msdn.microsoft.com/en-us/library/ff647070.aspx[^]

By combining the two, you can force all unauthorised users to have to login.

E.g in your web config...

XML
<authentication mode="Forms">
  <forms name="yourApplicationName"
         loginUrl="~/LogOn.aspx"
         path="/"
         protection="All"
         timeout="5"
         slidingExpiration="true"
         defaultUrl="~/Home.aspx"
         requireSSL="false"
         enableCrossAppRedirects="false"
         cookieless="UseCookies"/>
</authentication>
<authorization>
  <deny users="?"/>
</authorization>



The deny users ? element will stop all unauthorised users from accessing web pages, they will have to sign on first
 
Share this answer
 
Comments
senguptaamlan 29-Jun-11 6:52am    
good solution
[no name] 29-Jun-11 9:03am    
Nice Call. My 5 too.

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