• MOSS自定义登陆页面


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

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

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

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

      1 <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    2 <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
    3 <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    4 <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    5 <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    6 <%@ Import Namespace="Microsoft.SharePoint" %>
    7 <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    8 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomLogin.aspx.cs" Inherits="CustomLoginPageFBA.Layouts.CustomLoginPageFBA.CustomLogin" %>
    9
    10 <html>
    11 <head id="Head1" runat="server">
    12 <title>Login Page </title>
    13 <style>
    14 body
    15 {
    16 color: #000000;
    17 font: 12px/1.4 arial,FreeSans,Helvetica,sans-serif;
    18 margin: 0;
    19 }
    20 #LoginBox
    21 {
    22 margin: 0 auto;
    23 min-width: 200px;
    24 padding: 1em;
    25 width: 470px;
    26 margin-top: 100px;
    27 }
    28 #LoginBox .Form-Content
    29 {
    30 -moz-border-radius: 0.4em 0.4em 0.4em 0.4em;
    31 background-color: #FFFFFF;
    32 border: 1px solid #BBBBBB;
    33 min-height: 50px;
    34 padding: 1em;
    35 position: relative;
    36 }
    37 #LoginBox .Form-Content h2
    38 {
    39 border-bottom: medium none;
    40 color: #333333;
    41 font-size: 1.6em;
    42 margin: 0 0 1em;
    43 }
    44 #LoginBox .LoginTextField
    45 {
    46 -moz-border-radius: 0.3em 0.3em 0.3em 0.3em;
    47 border: 1px solid #DDDDDD;
    48 margin: 0;
    49 padding: 2px;
    50 width: 160px;
    51 }
    52 #LoginBox .LoginButton
    53 {
    54 -moz-border-radius: 0.3em 0.3em 0.3em 0.3em;
    55 line-height: 1.2;
    56 margin: 10px 10px 0 0;
    57 padding: 0 0.5em;
    58 }
    59 </style>
    60 </head>
    61 <body>
    62 <form id="form1" runat="server">
    63 <div style="clear: both;">
    64 </div>
    65
    66 <div id="LoginBox">
    67 <div class="Form-Content">
    68 <h2>
    69 Login</h2>
    70 <table width="100%" cellpadding="0" cellspacing="1">
    71 <tr>
    72 <td style=" 80px; white-space: nowrap; line-height: 2.4;">
    73 UserID:
    74 </td>
    75
    76 <td>
    77 <asp:textbox id="UserName" cssclass="LoginTextField" runat="server"></asp:textbox>
    78 </td>
    79 </tr>
    80 <tr>
    81 <td style=" 80px; white-space: nowrap; line-height: 2.4;">
    82 Password:
    83 </td>
    84 <td>
    85
    86 <asp:textbox id="Password" cssclass="LoginTextField" runat="server" textmode="Password"></asp:textbox>
    87 </td>
    88 </tr>
    89 <tr>
    90 <td>
    91 &nbsp;
    92 </td>
    93 <td>
    94 <asp:Label ID="lblError" runat="server"></asp:Label>
    95
    96 </td>
    97 </tr>
    98 <tr>
    99 <td>
    100 <asp:button id="Login" runat="server" cssclass="LoginButton" onclick="Login_Click"
    101 text="Submit" />
    102 </td>
    103 <td>
    104 </td>
    105 </tr>
    106 </table>
    107 <p>
    108 &nbsp;</p>
    109 </div>
    110 </div>
    111 </form>
    112 </body>
    113 </html>

      CustomerLogin.aspx.cs代码如下:

     1 using System;
    2 using Microsoft.SharePoint;
    3 using Microsoft.SharePoint.WebControls;
    4 using Microsoft.SharePoint.IdentityModel;
    5 using Microsoft.SharePoint.Security;

    6 namespace CustomLoginPageFBA.Layouts.CustomLoginPageFBA
    7 {
    8 public partial class CustomLogin : System.Web.UI.Page //LayoutsPageBase
    9 {
    10 protected void Page_Load(object sender, EventArgs e)
    11 {
    12 try
    13 {
    14 if (!IsPostBack)
    15 {
    16 if (string.IsNullOrEmpty(Request.QueryString["username"]))
    17 {
    18
    19 }
    20 else
    21 {
    22 this.UserName.Text = Request.QueryString["username"];
    23 this.Password.Text = Request.QueryString["password"];
    24 EventArgs da = new EventArgs();
    25 object obj = new object();
    26 Login_Click(obj, da);
    27 }
    28 }
    29 }
    30 catch (Exception ex)
    31 {
    32 Response.Write(ex.ToString());
    33
    34 }
    35
    36 }
    37
    38 protected void Login_Click(object sender, EventArgs e)
    39 {
    40 if (!(UserName.Text.Length > 0 && Password.Text.Length > 0))
    41 lblError.Text = "User Name or Password can not be empty!";
    42 else
    43 {
    44 //bool status = SPClaimsUtility.AuthenticateFormsUser(Context.Request.UrlReferrer, UserName.Text, Password.Text);
    45 bool status = SPClaimsUtility.AuthenticateFormsUser(Request.Url, UserName.Text, Password.Text);
    46 if (!status)// if auth failed
    47 {
    48 lblError.Text = "Wrong Userid or Password";
    49
    50 }
    51 else //if success
    52 {
    53 Response.Redirect("http://spsite/default.aspx"); //目标站点链接
    54
    55 }
    56
    57  
    58 }
    59 }
    60
    61 }
    62 }

      

  • 相关阅读:
    ES6中的解构赋值
    一·京京得水
    localStorage,sessionStorage和cookie的区别
    mondodb和mysql的区别
    Win10 x64连接Oracle
    JFinal项目实践(了如股掌)7
    JFinal项目实践(了如股掌)6
    JFinal项目实践(了如股掌)5
    JFinal项目实践(了如股掌)4
    JFinal项目实践(了如股掌)3
  • 原文地址:https://www.cnblogs.com/rimtd/p/2129464.html
Copyright © 2020-2023  润新知