Forms-based Authentication

Discussion in 'ASP .Net Security' started by bebop, Nov 21, 2003.

  1. bebop

    bebop Guest

    HI

    I'm using Forms-based Authentication and trying out the
    example from the book: "ASP.NET Professional Secrets"

    after downloading the c# code there was no code for
    chapter 15

    Can anyone provide the code for chapter 15 and what it
    includes?

    I tried entering the code from the chapter by hand but I
    can't get the program to work.

    code from book:

    <%@ Page language="C#"%>

    <script runat = "server">

    void btnLogin_Click(Object sender, EventArgs e) {
    if (txtUserName.Value == "User" &&
    txtPassword.Value == "Password")
    {
    FormsAuthentication.RedirectFromLoginPage
    (txtUserName.Value, chkSaveCookie.Checked);
    }
    else
    {
    divMessage.InnerText = "Invalid user name or
    password";
    }
    }
    </script>

    <html>
    <head>
    <title>Login Page</title>
    </head>
    <body>

    <form id="frmLogin" method="post" runat="server">
    User Name: <input type="text" id="txtUserName"
    name="txtUserName" runat="server">
    </p>
    Password: <input type="password" name="txtPassword"
    id="txtPassword" runat="server">
    <p/>

    <input type="checkbox" name="chkSaveCookie"
    id="chkSaveCookie" runat="server">Save my state
    <p/>

    <input type="button" name="btnLogin" runat="server"
    onserverclick="btnLogin_Click" value="Login">
    <p/>
    <div runat="server" id="divMessage"></div>
    </form>
    </body>
    </html>


    also books mentions to do the following in the Web.Config
    file:

    set the mode attribute to Forms and provide a loginUrl

    <authentication mode="Forms">
    <forms name="WileyAuth" loginUrl="LoginPage.aspx"
    path="/"> </forms>


    and add a location element as well:

    <location path="ProtectedPage.aspx">
    <system.web>
    <authorization>
    <deny users="?" />
    </authorization>
    </system.web>
    </location>


    Any help on Forms-based Authentication would be
    appreciated.

    bebop
    bebop, Nov 21, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vic

    forms-based authentication

    Vic, Oct 29, 2003, in forum: ASP .Net
    Replies:
    9
    Views:
    642
  2. Rob
    Replies:
    4
    Views:
    1,012
  3. Eric
    Replies:
    2
    Views:
    1,399
    Tommy
    Feb 13, 2004
  4. Keltex
    Replies:
    1
    Views:
    388
    Dominick Baier [DevelopMentor]
    Jan 24, 2006
  5. Eric
    Replies:
    2
    Views:
    466
Loading...

Share This Page