项目中有一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");  //跳转到一个内部页面
    ......
  }
}
......

解决方案 »

  1.   

    现在问题是用户名和密码正确的情况下任然跳转到login.aspx页面,好像未获取凭证一样。
      

  2.   

    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这样嘛。。你的验证错了,语句
      

  3.   

    you are probably not doing it right, did you create a cookie? see如何使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
    http://support.microsoft.com/kb/301240/zh-cn
      

  4.   

    回楼上:我并不需要跳转到用户请求的页面,所以我用GetAuthCookie给用户一个基于Cookie的凭证,另外我的页面上也没有CheckBox,用你的方法能行?
      

  5.   

    我改用了:FormsAuthentication.RedirectFromLoginPage(user.Text.Trim(),false);原来问题基本解决了,但它总默认跳转到Default.aspx,怎么让它跳转到Main.aspx?
      

  6.   

    多谢两位星星。搞定了,原来不能将inside设为虚拟目录,没注意,晚上在床上去慢慢想原因:)