Forms验证问题。
项目中有一inside目录,用户通过登录后可访问,拒绝匿名用户访问,Web.Config配置如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
......
</system.web>
<location path="inside">
<system.web>
<authentication mode="Forms">
<forms name=".ASPXAUTH" loginUrl="../login.aspx" protection="All" timeout="1440" path="/" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
</configuration>
然后login.aspx.cs中主要代码如下:
......
private void ok_Click(object sender, System.EventArgs e)
{
......
if(......) //如果用户名密码与数据库匹配
{
FormsAuthentication.GetAuthCookie(user.Text.Trim(),false); //给用户凭证(问题应该在此)
Response.Redirect("inside/main.aspx"); //跳转到一个内部页面
......
}
}
......
问题点数:50、回复次数:6Top
1 楼luck0235(风平浪静时人人都能掌舵)回复于 2005-04-22 21:06:11 得分 0
现在问题是用户名和密码正确的情况下任然跳转到login.aspx页面,好像未获取凭证一样。Top
2 楼hackate(兰花开香入梦境,独思佳人亦飘然!!)回复于 2005-04-22 21:13:26 得分 25
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text.Trim <> "" And TextBox2.Text.Trim <> "" Then
If TextBox1.Text = "hackate" And TextBox2.Text = "520520" Then
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, CheckBox1.Checked)
Else
Response.Write("<script>alert('用户名或者密码错误!');</script>")
End If
Else
Response.Write("<script>alert('不能为空');</script>")
End If
End Sub
这样嘛。。你的验证错了,语句Top
3 楼saucer(思归)回复于 2005-04-22 21:15:20 得分 25
you are probably not doing it right, did you create a cookie? see
如何使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
http://support.microsoft.com/kb/301240/zh-cnTop
4 楼luck0235(风平浪静时人人都能掌舵)回复于 2005-04-22 21:19:34 得分 0
回楼上:我并不需要跳转到用户请求的页面,所以我用GetAuthCookie给用户一个基于Cookie的凭证,另外我的页面上也没有CheckBox,用你的方法能行?Top
5 楼luck0235(风平浪静时人人都能掌舵)回复于 2005-04-22 22:35:22 得分 0
我改用了:FormsAuthentication.RedirectFromLoginPage(user.Text.Trim(),false);
原来问题基本解决了,但它总默认跳转到Default.aspx,怎么让它跳转到Main.aspx?Top
6 楼luck0235(风平浪静时人人都能掌舵)回复于 2005-04-22 22:40:29 得分 0
多谢两位星星。搞定了,原来不能将inside设为虚拟目录,没注意,晚上在床上去慢慢想原因:)Top





