簡體   English   中英

將表單驗證添加到ADFS登錄

[英]Adding Form Validation to ADFS Login

我需要檢查傳遞給我的adfs登錄頁面的表單變量,但是當我向內置的Page_Load函數添加任何內容時,它會中斷。

FormsSignIn.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true"  ValidateRequest="false"
    CodeFile="FormsSignIn.aspx.cs" Inherits="FormsSignIn" Title="<%$ Resources:CommonResources, FormsSignInPageTitle%>"
    EnableViewState="false" runat="server"%>
<%@ OutputCache Location="None" %>

<asp:Content ID="FormsSignInContent" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="GroupXLargeMargin"><asp:Label Text="<%$ Resources:CommonResources, FormsSignInHeader%>" runat="server" /></div>
    <h3>*******I Want lbl1.Text to output here from the codefile.</h3>
    <table class="UsernamePasswordTable">
        <tr>
            <td>
                <span class="Label"><asp:Label Text="<%$ Resources:CommonResources, UsernameLabel%>" runat="server" /></span>
            </td>
            <td>
                <asp:TextBox runat="server" ID="UsernameTextBox" ></asp:TextBox>            
            </td>
            <td class="TextColorSecondary TextSizeSmall">
                <asp:Label Text="<%$ Resources:CommonResources, UsernameExample%>" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                <span class="Label"><asp:Label Text="<%$ Resources:CommonResources, PasswordLabel%>" runat="server" /></span>
            </td>
            <td>
                <asp:TextBox runat="server" ID="PasswordTextBox" TextMode="Password" ></asp:TextBox>            
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td></td>
            <td colspan="2" class="TextSizeSmall TextColorError">
                <asp:Label ID="ErrorTextLabel" runat="server" Text="" Visible="False"></asp:Label>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <div class="RightAlign GroupXLargeMargin">
                    <asp:Button ID="SubmitButton" runat="server" Text="<%$ Resources:CommonResources, FormsSignInButtonText%>" OnClick="SubmitButton_Click" CssClass="Resizable"/>
                </div>
            </td>
            <td>&nbsp;</td>
        </tr>
    </table>
</asp:Content>

FormsSignIn.Aspx.cs

using System;
using Microsoft.IdentityServer.Web;
using Microsoft.IdentityServer.Web.UI;

public partial class FormsSignIn : FormsLoginPage
{
    protected void Page_Load( object sender, EventArgs e )
    {
            //Uncommented, this breaks!!!!!!!!!!!!!!
        /* if ( !string.IsNullOrEmpty(Page.Request.Form["foo"]) ) {
                lbl1.Text = Page.Request.Form["foo"].Trim();
        } else {
                lbl1.Text = "not found";
            } */
    }

    protected void HandleError( string message )
    {
        ErrorTextLabel.Visible = true;
        ErrorTextLabel.Text = Resources.CommonResources.IncorrectUsernameText;
    }

    protected void SubmitButton_Click( object sender, EventArgs e )
    {
        try
        {
            SignIn( UsernameTextBox.Text, PasswordTextBox.Text );
        }
        catch ( AuthenticationFailedException ex )
        {
            HandleError( ex.Message );
        }
    }
}

您沒有提到如何添加代碼或代碼如何中斷,但是總的來說,直接修改文件時發現了問題。

鑒於ADFS只是另一個IIS應用程序,我對采用這種方法感到更加高興:

修改和保護ADFS 2 Web應用程序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM