表单身份验证问题 - 身份验证后无法从登录页面重定向到主页

时间:2012-05-14 10:40:52

标签: c# .net sharepoint-2010 forms-authentication

在Sharepoint 2010中,我们使用经典身份验证创建了一个Web应用程序并开始开发它。稍后,我们希望对项目实现表单身份验证,因此我创建了一个新的SharePoint Web应用程序,并启用了基于表单的身份验证。我拿了旧网站的备份(经典版权所有)并恢复到新网站(fba)。我按照以下链接实现了表单身份验证:

Configuring Forms Based Authentication for SharePoint 2010 using IIS7

我创建了一个自定义登录页面。输入有效凭据后,用户不会重定向到主页。身份验证正常进行,但不会重定向到主页。当我点击登录按钮时,它再次加载相同的登录页面。请找到以下代码进行身份验证和重定向到主页:

protected void btnLogin2_Click(object sender, EventArgs e)
{
  if (Membership.ValidateUser(txtUserId.Value, txtPassword.Value))
  {
    string link = "http://ejudnam:36414/sites/Prototype/Dashboard/Pages/default.aspx");

    Response.Redirect(link);

    //I tried with the below line also but it is of no use
    // SPUtility.Redirect(link, SPRedirectFlags.Default, this.Context);
  }  
  else
  {
    lblMessage.Text = "Login Failed.";
  }
}

我们无法弄清楚这个问题。我尝试了很多解决方案,但它们毫无用处。

1 个答案:

答案 0 :(得分:2)

请使用SPClaimsUtility在基于声明的应用程序中授权用户。

  

从。\ assembly \ GAC_MSIL \ Microsoft.SharePoint.IdentityModel \ 14.0.0.0__71e9bce111e9429c \ Microsoft.SharePoint.IdentityModel.dll添加 Microsoft.SharePoint.IdentityModel DLL引用以访问SPClaimsUtility

试试这个:

  SPSecurity.RunWithElevatedPrivileges(delegate()
        {
           bool status = SPClaimsUtility.AuthenticateFormsUser(Context.Request.UrlReferrer, txtUserId.Value, txtPassword.Value);
           if (status)
              {
               string link = "http://ejudnam:36414/sites/Prototype/Dashboard/Pages/default.aspx";
              Response.Redirect(link);
              }
        });