ASP.Net Membership System - Login

  1. #1

    ASP.Net Membership System - Login

    Hey, After a little work I've added the asp.net membership functionality to a login window. Any help or improvements welcome

    VB.Net:

    
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="DriveBusiness_Tracking._Default" %>
    
    <%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
    <%@ Register assembly="Devart.Data.Mysql" namespace="Devart.Data.Mysql" tagprefix="ddm" %>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
    
        Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As Coolite.Ext.Web.AjaxEventArgs)
    
            'We need to determine if the user is authenticated and set e.Authenticated accordingly
            'Get the values entered by the user
            Dim loginUsername As String = Username.Text
            Dim loginPassword As String = Password.Text
    
            'determine if the user's username/password are valid
            If Membership.ValidateUser(loginUsername, loginPassword) Then
                FormsAuthentication.SetAuthCookie(loginUsername, True)
                Response.Redirect("/desktop.aspx")
            Else
                e.Success = False
                e.ErrorMessage = "Invalid Username or Password"
            End If
    
        End Sub
        
        
       </script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="loginhead" runat="server">
        <title>Login</title>
        
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:Login ID="Login1" runat="server" Width="312px">
            <LayoutTemplate>
                <ext:ScriptManager ID="ScriptManager1" runat="server" />
                    <ext:Window ID="LoginWindow" runat="server" Closable="false" Resizable="false" Height="150" Icon="Lock" Title="Login" Draggable="false" Width="350" Modal="true" BodyStyle="padding:5px;">
                        <Body>
                            <ext:FormLayout ID="FormLayout1" runat="server">
                                <ext:Anchor Horizontal="100%">
                                    <ext:TextField  ID="Username" runat="server" ReadOnly="false" FieldLabel="Username" AllowBlank="false" BlankText="Your username is required." />
                                </ext:Anchor>
                                <ext:Anchor Horizontal="100%">
                                    <ext:TextField ID="Password" runat="server" ReadOnly="false" InputType="Password" FieldLabel="Password" AllowBlank="false" BlankText="Your password is required." />
                                </ext:Anchor>
                                <ext:Anchor Horizontal="100%">
                                    <ext:Checkbox id="RememberMe" runat="server" ReadOnly="false" FieldLabel="Remember Me" />
                                </ext:Anchor>
                            </ext:FormLayout>
                        </body>
                        <Buttons>
                            <ext:Button ID="LoginButton" ValidationGroup="Login1" runat="server" CommandName="Login1.Authenticate" Text="Login" Icon="Accept">
                                <AjaxEvents>
                                   <Click OnEvent="Login1_Authenticate"></Click>
                                </AjaxEvents>                     
                            </ext:Button>
                        </Buttons>
                    </ext:Window>
                </LayoutTemplate>
           </asp:Login>
        </form>
    </body>
    
    </html>

    C#

    
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="DriveBusiness_Tracking._Default" %>
    
    <%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
    <%@ Register assembly="Devart.Data.Mysql" namespace="Devart.Data.Mysql" tagprefix="ddm" %>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        protected void Login1_Authenticate(object sender, Coolite.Ext.Web.AjaxEventArgs e)
    {
               
        //We need to determine if the user is authenticated and set e.Authenticated accordingly
        //Get the values entered by the user
        string loginUsername = Username.Text;
        string loginPassword = Password.Text;
    
        //determine if the user's username/password are valid
        if (Membership.ValidateUser(loginUsername, loginPassword)) {
            FormsAuthentication.SetAuthCookie(loginUsername, true);
            Response.Redirect("/desktop.aspx");
        }
        else {
            e.Success = false;
            e.ErrorMessage = "Invalid Username or Password";
            
        }
    }
        
       </script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="loginhead" runat="server">
        <title>Login</title>
        
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:Login ID="Login1" runat="server" Width="312px">
            <LayoutTemplate>
                <ext:ScriptManager ID="ScriptManager1" runat="server" />
                    <ext:Window ID="LoginWindow" runat="server" Closable="false" Resizable="false" Height="150" Icon="Lock" Title="Login" Draggable="false" Width="350" Modal="true" BodyStyle="padding:5px;">
                        <Body>
                            <ext:FormLayout ID="FormLayout1" runat="server">
                                <ext:Anchor Horizontal="100%">
                                    <ext:TextField  ID="Username" runat="server" ReadOnly="false" FieldLabel="Username" AllowBlank="false" BlankText="Your username is required." />
                                </ext:Anchor>
                                <ext:Anchor Horizontal="100%">
                                    <ext:TextField ID="Password" runat="server" ReadOnly="false" InputType="Password" FieldLabel="Password" AllowBlank="false" BlankText="Your password is required." />
                                </ext:Anchor>
                                <ext:Anchor Horizontal="100%">
                                    <ext:Checkbox id="RememberMe" runat="server" ReadOnly="false" FieldLabel="Remember Me" />
                                </ext:Anchor>
                            </ext:FormLayout>
                        </body>
                        <Buttons>
                            <ext:Button ID="LoginButton" ValidationGroup="Login1" runat="server" CommandName="Login1.Authenticate" Text="Login" Icon="Accept">
                                <AjaxEvents>
                                   <Click OnEvent="Login1_Authenticate"></Click>
                                </AjaxEvents>                     
                            </ext:Button>
                        </Buttons>
                    </ext:Window>
                </LayoutTemplate>
           </asp:Login>
        </form>
    </body>
    
    </html>
    Hope this helps
  2. #2

    RE: ASP.Net Membership System - Login

    Thanks for posting this example!

    Geoffrey McGill
    Founder
  3. #3

    RE: ASP.Net Membership System - Login

    No problem geoffrey,

    If i get some time over the weekend I'm looking at possibly creating a new <ext:loginwindow> control

    Just need to have a proper look through the coolite source

  4. #4

    RE: ASP.Net Membership System - Login

    Hello Craig,

    Good work! I'm looking forward to use your Login Control :)

    FYI, I'm working on a web application that need "Forgot Password", "Add New User" and "Change Password" features. Do you have any sample on these?

    Thanks.

    Regards,
    JeeShen Lee
    +012- 904 2869
  5. #5

    Has this been updated or used by anyone successfully?

    I am trying to use this to replace my normal asp.net logon page but am getting a few errors. It does not recognize the scriptmanager, or AjaxEvents and the username and password fields do not get picked up as being declared.

    I am using VS2010, Asp.Net 4.0 and VB for my site design. I am also doing Forms Auth and would really love to replace my current ugly log on window with a nice pretty looking ext window.

    Thanks
  6. #6
    Hi,

    Forms auth forbides access to ext.net http handler. Please see the following topic to solve it

    http://forums.ext.net/showthread.php...TNET-resources
  7. #7

    'Username' and 'Password' does not exist in the current context!

    Hi Vlad,

    I´m trying to implement this sample but the username and password fields are not recognized. I read the link above you post, with no luck...

    The web.config already have:

    <configuration>
        <configSections>
            <section name="extnet" type="Ext.Net.GlobalConfig" requirePermission="false" />
        </configSections>
        
        <system.web>
            <httpHandlers>
                <add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false"/>
            </httpHandlers>
        </system.web> 
         ....
    </configuration>
    also I added the permissions in the web.config:
        <location path="extjs">
            <system.web>
                <authorization>
                    <allow users="*" />
                </authorization>
            </system.web>
        </location>
          <location path="extnet">
            <system.web>
                <authorization>
                    <allow users="*" />
                </authorization>
            </system.web>
        </location>
        <location path="icons">
            <system.web>
                <authorization>
                    <allow users="*" />
                </authorization>
            </system.web>
        </location>
        <location path="ux">
            <system.web>
                <authorization>
                    <allow users="*" />
                </authorization>
            </system.web>
        </location>
    I´m using ext.net v1, VS2010 and .net 4.

    Any suggestions? Thanks!

Similar Threads

  1. Replies: 4
    Last Post: Feb 01, 2011, 11:54 AM
  2. ASP.NET Membership Provider Problem
    By gayancc in forum 1.x Help
    Replies: 0
    Last Post: Jan 15, 2011, 8:47 AM
  3. login problem with Ext Login Control
    By Bruce2010 in forum 1.x Help
    Replies: 1
    Last Post: Nov 30, 2010, 4:35 PM
  4. asp.net membership provider
    By kikopico in forum 1.x Help
    Replies: 3
    Last Post: Mar 04, 2010, 7:00 AM
  5. Replies: 2
    Last Post: Aug 31, 2009, 6:03 PM

Posting Permissions