• SharePoint MOSS自定义登陆页面


    为了做MOSS FORM验证的单点登陆,而原有的FORM登陆页面没办法POST来登陆,几经挫折,终于有了新的思路,就是在MOSS系统创建一个页面来接收数据,然后通过membership生成凭证来实现单点。

    今天忘忧草实现了自定义页面登陆MOSS的例子,我做了些修改使之可以POST来登陆,也可以手动登陆

    注:这里验证主要是MOSS自带的验证,如果你是第三方系统,必须在第三方系统里做映射(第三方系统的帐号跟MOSS系统的帐号对应)来验证,传参还是得传MOSS的帐号

    用VS创建feature,添加页面CustomerLogin.aspx,代码如下

    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomLogin.aspx.cs" Inherits="CustomLoginPageFBA.Layouts.CustomLoginPageFBA.CustomLogin" %>

    <html>
    <head id="Head1" runat="server">
    <title>Login Page </title>
    <style>
    body
    {
    color: #000000;
    font: 12px/1.4 arial,FreeSans,Helvetica,sans-serif;
    margin: 0;
    }
    #LoginBox
    {
    margin: 0 auto;
    min- 200px;
    padding: 1em;
    470px;
    margin-top: 100px;
    }
    #LoginBox .Form-Content
    {
    -moz-border-radius: 0.4em 0.4em 0.4em 0.4em;
    background-color: #FFFFFF;
    border: 1px solid #BBBBBB;
    min-height: 50px;
    padding: 1em;
    position: relative;
    }
    #LoginBox .Form-Content h2
    {
    border-bottom: medium none;
    color: #333333;
    font-size: 1.6em;
    margin: 0 0 1em;
    }
    #LoginBox .LoginTextField
    {
    -moz-border-radius: 0.3em 0.3em 0.3em 0.3em;
    border: 1px solid #DDDDDD;
    margin: 0;
    padding: 2px;
    160px;
    }
    #LoginBox .LoginButton
    {
    -moz-border-radius: 0.3em 0.3em 0.3em 0.3em;
    line-height: 1.2;
    margin: 10px 10px 0 0;
    padding: 0 0.5em;
    }
    </style>
    </head>
    <body>
    <form id="form1" runat="server">
    <div style="clear: both;">
    </div>

    <div id="LoginBox">
    <div class="Form-Content">
    <h2>
    Login</h2>
    <table width="100%" cellpadding="0" cellspacing="1">
    <tr>
    <td style=" 80px; white-space: nowrap; line-height: 2.4;">
    UserID:
    </td>

    <td>
    <asp:textbox id="UserName" cssclass="LoginTextField" runat="server"></asp:textbox>
    </td>
    </tr>
    <tr>
    <td style=" 80px; white-space: nowrap; line-height: 2.4;">
    Password:
    </td>
    <td>

    <asp:textbox id="Password" cssclass="LoginTextField" runat="server" textmode="Password"></asp:textbox>
    </td>
    </tr>
    <tr>
    <td>
    &nbsp;
    </td>
    <td>
    <asp:Label ID="lblError" runat="server"></asp:Label>

    </td>
    </tr>
    <tr>
    <td>
    <asp:button id="Login" runat="server" cssclass="LoginButton" onclick="Login_Click"
    text="Submit" />
    </td>
    <td>
    </td>
    </tr>
    </table>
    <p>
    &nbsp;</p>
    </div>
    </div>
    </form>
    </body>
    </html>

    CustomerLogin.aspx.cs代码如下:

    using System;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    using Microsoft.SharePoint.IdentityModel;
    using Microsoft.SharePoint.Security;
    namespace CustomLoginPageFBA.Layouts.CustomLoginPageFBA
    {
    public partial class CustomLogin : System.Web.UI.Page //LayoutsPageBase
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    try
    {
    if (!IsPostBack)
    {
    if (string.IsNullOrEmpty(Request.QueryString["username"]))
    {

    }
    else
    {
    this.UserName.Text = Request.QueryString["username"];
    this.Password.Text = Request.QueryString["password"];
    EventArgs da = new EventArgs();
    object obj = new object();
    Login_Click(obj, da);
    }
    }
    }
    catch (Exception ex)
    {
    Response.Write(ex.ToString());

    }

    }

    protected void Login_Click(object sender, EventArgs e)
    {
    if (!(UserName.Text.Length > 0 && Password.Text.Length > 0))
    lblError.Text = "User Name or Password can not be empty!";
    else
    {
    //bool status = SPClaimsUtility.AuthenticateFormsUser(Context.Request.UrlReferrer, UserName.Text, Password.Text);
    bool status = SPClaimsUtility.AuthenticateFormsUser(Request.Url, UserName.Text, Password.Text);
    if (!status)// if auth failed
    {
    lblError.Text = "Wrong Userid or Password";

    }
    else //if success
    {
    Response.Redirect("http://spsite/default.aspx"); //目标站点链接

    }


    }
    }

    }
    }

  • 相关阅读:
    java基础之接口和多态
    JAVA随笔三
    java基础之多线程
    JAVA随笔二
    java基础之继承补充和抽象类
    java基础之面向对象和继承
    java基础 之IO流随笔
    Java 基础之String随笔
    JAVA随笔一
    python文件处理指针的移动
  • 原文地址:https://www.cnblogs.com/martin-roger/p/5477095.html
Copyright © 2020-2023  润新知