想要对多用户进行身份验证,并且拒绝任何用户进入网站,而无需通过抛出登录页面 [英] iwant to do authencation for multi user and deny any user to enter to site whithout pass throw log in page

查看:35
本文介绍了想要对多用户进行身份验证,并且拒绝任何用户进入网站,而无需通过抛出登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对多用户进行身份验证,并拒绝任何用户进入该页面,而无需通过登录页面
为可能的站点添加安全性,并拒绝任何用户传递到没有传递登录页面的站点页面] \
answe非常漂亮,我有很多现成的代码


但是我想从您的代码中获取密码,如果我们拒绝用户,则无人可以输入我想创建新用户

并输入姓名,并将用户名存储在数据库中


我会但可能会编码


SqlConnection c;
SqlCommand m;
SqlDataReader r;

公共无效get_con()
{
c =新的SqlConnection();
c.ConnectionString = @数据源=.\ SQLEXPRESS; AttachDbFilename = | DataDirectory | \ pard.mdf;集成安全性= True;用户实例= True";
}

受保护的void Page_Load(对象发送者,EventArgs e)
{
get_con();
}


受保护的void Button1_Click(对象发送者,EventArgs e)
{


m =新的SqlCommand();
c.Open();
m.Connection = c;

m.Parameters.Add("@ a",TextBox2name.Text);
m.CommandText =从[用户]中选择[prd],其中nam = @ a";


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

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




}

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();




}

推荐答案

一起看看ASP.Net授权和.Net表单身份验证

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

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

通过将两者结合起来,可以强制所有未经授权的用户必须登录.

例如,在您的Web配置中...

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

<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


这篇关于想要对多用户进行身份验证,并且拒绝任何用户进入网站,而无需通过抛出登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆