zoukankan      html  css  js  c++  java
  • 实现一个简单的Form授权 How to: Implement Simple Forms Authentication

    Form授权OverView:     http://msdn.microsoft.com/en-us/library/9wff0kyh.aspx

    http://msdn.microsoft.com/en-us/library/xdt4thhy

    How to: Implement Simple Forms Authentication

     

    <system.web>
    <authentication mode="Forms">
    <forms loginUrl="logon.aspx" name=".ASPXFORMSAUTH">
    </forms>
    </authentication>
    <authorization>
    <deny users="?" />
    </authorization>
    </system.web>

     

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Web.Security" %>

    <script runat="server">
    void Logon_Click(object sender, EventArgs e)
    {
    if ((UserEmail.Text == "jchen@contoso.com") &&
    (UserPass.Text
    == "37Yj*99Ps"))
    {
    FormsAuthentication.RedirectFromLoginPage
    (UserEmail.Text, Persist.Checked);
    }
    else
    {
    Msg.Text
    = "Invalid credentials. Please try again.";
    }
    }
    </script>
    <html>
    <head id="Head1" runat="server">
    <title>Forms Authentication - Login</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <h3>
    Logon Page
    </h3>
    <table>
    <tr>
    <td>
    E-mail address:
    </td>
    <td>
    <asp:TextBox ID="UserEmail" runat="server" /></td>
    <td>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
    ControlToValidate
    ="UserEmail"
    Display
    ="Dynamic"
    ErrorMessage
    ="Cannot be empty."
    runat
    ="server" />
    </td>
    </tr>
    <tr>
    <td>
    Password:
    </td>
    <td>
    <asp:TextBox ID="UserPass" TextMode="Password"
    runat
    ="server" />
    </td>
    <td>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2"
    ControlToValidate
    ="UserPass"
    ErrorMessage
    ="Cannot be empty."
    runat
    ="server" />
    </td>
    </tr>
    <tr>
    <td>
    Remember me?
    </td>
    <td>
    <asp:CheckBox ID="Persist" runat="server" /></td>
    </tr>
    </table>
    <asp:Button ID="Submit1" OnClick="Logon_Click" Text="Log On"
    runat
    ="server" />
    <p>
    <asp:Label ID="Msg" ForeColor="red" runat="server" />
    </p>
    </form>
    </body>
    </html>

     

     

    <%@ Page Language="C#" %>
    <html>
    <head>
    <title>Forms Authentication - Default Page</title>
    </head>

    <script runat="server">
    void Page_Load(object sender, EventArgs e)
    {
    Welcome.Text
    = "Hello, " + Context.User.Identity.Name;
    }

    void Signout_Click(object sender, EventArgs e)
    {
    FormsAuthentication.SignOut();
    Response.Redirect(
    "Logon.aspx");
    }
    </script>

    <body>
    <h3>
    Using Forms Authentication
    </h3>
    <asp:Label ID="Welcome" runat="server" />
    <form id="Form1" runat="server">
    <asp:Button ID="Submit1" OnClick="Signout_Click"
    Text
    ="Sign Out" runat="server" /><p>
    </form>
    </body>
    </html>

     

     

     

  • 相关阅读:
    一维函数指针数组和二维函数指针数组demo
    等着新工作
    SSRS常见问题解决方案
    速度
    javascript 满足多层treeview的各种勾选
    vue create 初步解析以及定制化修改
    leveldb总结
    秋招总结场景设计题
    NOSQL: mongoDB windows
    更新webconfig配置文件
  • 原文地址:https://www.cnblogs.com/wucg/p/1963839.html
Copyright © 2011-2022 走看看