_登陆验证的问题,我在登陆页面输入用户名和密码后登陆Default.aspx,
然后我在注销退出,当我试验着用输入网地址的方法后竟然还可以登陆,登陆后虽然其他操作都不可以了,如果刷新一次就不能登陆,但是我希望注销后是绝对不能进入,我的代码有什么问题请指教!
_________________________________________________
Web.Config<?xml version="1.0"?>
<!--
注意: 除了手动编辑此文件以外,您还可以使用
Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表在
machine.config.comments 中,该文件通常位于
\Windows\Microsoft.Net\Framework\v2.x\Config 中
-->
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
设置 compilation debug="true" 将调试符号插入
已编译的页面中。但由于这会
影响性能,因此只在开发过程中将此值
设置为 true。
-->
<compilation debug="true"/>
<!--
通过 <authentication> 节可以配置 ASP.NET 使用的
安全身份验证模式,
以标识传入的用户。
-->
<authentication mode="Forms">
<forms loginUrl="landing.aspx" defaultUrl="Default.aspx" name=".ASPXAUTH" >
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</configuration>
_________________________________________________________________________
landing.aspx protected SqlConnection createLoginConn()
{
SqlConnection cn = new SqlConnection("server=.;database=Login;uid=sa;pwd=xxx");
return cn;
}
protected void Button1_Click(object sender, EventArgs e)
{
string UserName = this.TextBox1.Text;
string Password = this.TextBox2.Text;
SqlConnection cn = createLoginConn();
cn.Open();
SqlCommand cmd = new SqlCommand
("select count(*) from tb_login where Name=@Name and Pass=@Pass ", cn);
cmd.Parameters.Add("@Name", SqlDbType.VarChar, 50).Value = UserName;
//MD5加密
cmd.Parameters.Add("@Pass", SqlDbType.VarChar, 50).Value =
FormsAuthentication.HashPasswordForStoringInConfigFile(Password, "MD5");
int i = (int)cmd.ExecuteScalar();
if (i > 0)
{
//添加登陆日志
//Response.Write("登陆成功!");
cmd = new SqlCommand("insert EntryLog values('" + TextBox1.Text + "','" + DateTime.Now.ToString() + "')",cn);
cmd.ExecuteNonQuery();
cn.Close();
Session["name"] = this.TextBox1.Text;
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
Response.Redirect("Default.aspx"); }
else
{
Response.Write("登陆失败!"); } }
___________________________________________________________________________________
Default.aspxprotected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["name"] != null)
{
//查询数据....略>
}
else
{
Response.Redirect("landing.aspx");
}
}
else
{
Response.Redirect("landing.aspx");
}
Session.Clear(); } //注销用户
protected void Button2_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect("landing.aspx");
}
}
____________________________________________________________________
然后我在注销退出,当我试验着用输入网地址的方法后竟然还可以登陆,登陆后虽然其他操作都不可以了,如果刷新一次就不能登陆,但是我希望注销后是绝对不能进入,我的代码有什么问题请指教!
_________________________________________________
Web.Config<?xml version="1.0"?>
<!--
注意: 除了手动编辑此文件以外,您还可以使用
Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表在
machine.config.comments 中,该文件通常位于
\Windows\Microsoft.Net\Framework\v2.x\Config 中
-->
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
设置 compilation debug="true" 将调试符号插入
已编译的页面中。但由于这会
影响性能,因此只在开发过程中将此值
设置为 true。
-->
<compilation debug="true"/>
<!--
通过 <authentication> 节可以配置 ASP.NET 使用的
安全身份验证模式,
以标识传入的用户。
-->
<authentication mode="Forms">
<forms loginUrl="landing.aspx" defaultUrl="Default.aspx" name=".ASPXAUTH" >
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</configuration>
_________________________________________________________________________
landing.aspx protected SqlConnection createLoginConn()
{
SqlConnection cn = new SqlConnection("server=.;database=Login;uid=sa;pwd=xxx");
return cn;
}
protected void Button1_Click(object sender, EventArgs e)
{
string UserName = this.TextBox1.Text;
string Password = this.TextBox2.Text;
SqlConnection cn = createLoginConn();
cn.Open();
SqlCommand cmd = new SqlCommand
("select count(*) from tb_login where Name=@Name and Pass=@Pass ", cn);
cmd.Parameters.Add("@Name", SqlDbType.VarChar, 50).Value = UserName;
//MD5加密
cmd.Parameters.Add("@Pass", SqlDbType.VarChar, 50).Value =
FormsAuthentication.HashPasswordForStoringInConfigFile(Password, "MD5");
int i = (int)cmd.ExecuteScalar();
if (i > 0)
{
//添加登陆日志
//Response.Write("登陆成功!");
cmd = new SqlCommand("insert EntryLog values('" + TextBox1.Text + "','" + DateTime.Now.ToString() + "')",cn);
cmd.ExecuteNonQuery();
cn.Close();
Session["name"] = this.TextBox1.Text;
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
Response.Redirect("Default.aspx"); }
else
{
Response.Write("登陆失败!"); } }
___________________________________________________________________________________
Default.aspxprotected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["name"] != null)
{
//查询数据....略>
}
else
{
Response.Redirect("landing.aspx");
}
}
else
{
Response.Redirect("landing.aspx");
}
Session.Clear(); } //注销用户
protected void Button2_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect("landing.aspx");
}
}
____________________________________________________________________
解决方案 »
- 大哥哥,大姐姐:请提供一个存储过程,具有多表查询和group by以及多字段排序功能,顺便帮我看下如下问题,谢谢啊
- GridView问题
- vista装vs2005怎么样,有没有人成功装过!
- 关于asp.net 2.0事件回发的问题?
- 求:一次下载多个Execl文件的例子
- 急啊~~~GridView中列宽问题
- 请教一个问题,我如果不用.net编辑器来写代码,而是用asp.net web matrix来写得话,需要写那些文件??
- 用datagrid实现编缉,修改,取消功能时验证控件问题?
- 散200分邀高手解决csdn未能解决的动态生成控件并保存问题,泽备后人!(up有分)
- DataList控件中如何绑定图片
- VS2008使用哪个版本???
- 调用DLL文件[菜鸟问题]
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Response.Expires = 0;
Response.CacheControl = "no-cache";
Response.Cache.SetNoStore();
{
if (Session["name"] != null)
{
}
else
{
Response.Redirect("landing.aspx");
} if (!IsPostBack)
{
//查询数据....略>
}
else
{
Response.Redirect("landing.aspx");
}
Session.Clear(); } //注销用户
protected void Button2_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect("landing.aspx");
}
}