Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > BOOK: Beginning ASP.NET 1.0
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 24th, 2003, 10:46 AM
Registered User
 
Join Date: Sep 2003
Location: Chicago, IL, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 20 -Forms based Authentication

I have typed the following code, and also downloaded the code and get the same results with both.

When I navigate to the default.aspx page the login.aspx page displays first. When I type in an invalid name and password I get the expected prompts. But when I type in the correct name and password, the login page re-displays with the name filled out and the password text box blank with nor error prompts. The default.aspx page is never displayed.

Here the 3 files

web.config

<configuration>
    <system.web>
        <authentication mode="Forms">
        <forms name=".WroxDemo" loginUrl="login.aspx"
        protection="All" timeout="60" />
        </authentication>
        <machineKey validationKey="AutoGenerate"
        decryptionKey="AutoGenerate" validation="SHA1"/>
        <authorization>
            <deny users="?" />
        </authorization>
        <customErrors mode="Off"/>
    </system.web>
</configuration>

login.aspx

<%@ Import Namespace="system.Web.Security " %>
<html>
<head>
<script language="VB" runat="server">
    Sub Login_Click(Src as Object, E as EventArgs)
        If Page.IsValid Then
            if txtEmail.Text = "Wrox" and txtPwd.Text = "MyPass" Then
                FormsAuthentication.RedirectFromLoginPage(txtEmail .Text,true)
            else
                lblLoginMsg.Text = "Use Wrox as user name and password as " & _
                                            "MyPass. Please try again."
            end if
        End If
    End Sub
</script>

</head>
<body>
<form runat="server">
<h1>Using Form based Authentication<BR>with Pre-defined Credentials</h1>
Users Name:

<asp:textbox id="txtEmail" runat="server" />
*

<asp:RequiredFieldValidator
    ControlToValidate="txtEmail"
    Display="Dynamic"
    ErrorMessage="Login name can't be empty."
    runat="server"/>

 Password:

<asp:textbox TextMode="Password" id="txtPwd" runat="server" />
     *
<asp:RequiredFieldValidator
    ControlToValidate="txtPWD"
    Display="Dynamic"
    ErrorMessage="Password can't be empty."
    runat="server"/>



<asp:Label
    id="lblLoginMsg"
    ForeColor="Red"
    Font-Name="Verdana";
    Font-Size="10"
    runat="server" />



<asp:button
    id="btnLogin"
    Text="Login"
    OnClick="Login_Click"
    runat=Server />
</form>
</body>
</html>


default.aspx

<%@ Import Namespace="system.Web.Security " %>
<html>
<head>
<script language="VB" runat="server">
    Sub Page_Load(Src As Object, E As EventArgs)
        lblUser.Text = "Your usr name is: " & User.Identity.Name
        lblType.Text = "Your Authentication type is: " & _
            User.Identity.AuthenticationType
    End Sub

    Sub Logout_click(Src As Object, E as EventArgs)
        FormsAuthentication.SignOut()
        Server.Transfer("login.aspx)
    End Sub
</script>
</head>
<body>
    <form runat="server">
        <asp:label id="lblUser" runat="server"/>

        <asp:label id="lblType" runat="server"/>

        <asp:Button text="Logout" OnClick="Logout_Click" runat="server"/>
    </form>
</body>
</html>

The IIS server is installed locally on a WIN2K professional desktop with Visual studio.net installed. (to get the .NET framework)

I used the IIS MMC New Virtual Folder wizard to create the virtual folder accepting all of the defaults.

any help you can provide is much appreciated!

Bill

  #2 (permalink)  
Old September 24th, 2003, 10:52 AM
Registered User
 
Join Date: Sep 2003
Location: Chicago, IL, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

More Info...

When I use localhost in the url everything works fine, but when I use my IP address or computer name I get redirected back to the login page.

Bill

  #3 (permalink)  
Old October 7th, 2003, 09:17 AM
Authorized User
 
Join Date: Oct 2003
Location: Phoenix, Arizona, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

bshay,

I took your code and it worked on my machine. However, you may want to pay attention to the following code:

Sub Logout_click(Src As Object, E as EventArgs)
        FormsAuthentication.SignOut()
        Server.Transfer("login.aspx)
    End Sub

You're missing a close quote. Now I don't know if this was a typo or you copy and pasted and this is in your code but you need to check it out. As for the machine name thing I had no problems with it working under my machine name or localhost. Check your IIS configuration. Create a test virtual directory if needed to test it out.

Jason

"Is the glass half full, half empty, or twice as large as it needs to be?"

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET 1.0 Chapter 20 Custom Authentication and . rjwelte .NET Web Services 0 September 2nd, 2004 07:31 PM
chapter 20 basic authentication egivler BOOK: Beginning ASP.NET 1.0 3 June 29th, 2004 09:16 PM
Chapter 20 masegui JSP Basics 0 April 1st, 2004 07:54 AM



All times are GMT -4. The time now is 05:57 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.