开发者

binding user and password

开发者 https://www.devze.com 2023-03-22 02:25 出处:网络
I have a question about the login control of asp.net. I defined on my application in asp.Login, and password, also I made the changes in the web config with the info needed to set the authentication b

I have a question about the login control of asp.net. I defined on my application in asp.Login, and password, also I made the changes in the web config with the info needed to set the authentication but i want to know how i bind the fields of user and password to the data base: I have this doubt because in the msdn documentation says "If you use the Login control with ASP.NET membership, you do not need to write code to perform authentication.".

Here's the code of my view

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/MasterSencillo.master"     AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="MapaPrueba.login" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table class="tlbLogin">
    <tr>
        <td>
        <asp:Login ID="lgnMapZone" runat="server" DestinationPageUrl="~/Default.aspx" 
                LoginButtonText="Iniciar Sesion" 
                PasswordRequiredErrorMessage="Password requerido." RememberMeText="Recuerdáme" 
                TitleText="Inicio de Session " UserNameLabelText="Usuario:" 
                UserNameRequiredErrorMessage="Nombre de usuario Requerido">
            <LabelStyle CssClass="formatText" />
            <TitleTextStyle CssClass="formatText" />
            </asp:Login>
        </td>
    </tr>
</table>

And my Web.Config

<appSettings/>
<connectionStrings>
    <add name="MySqlConnection" connectionString="Data Source=.\SqlExpress;开发者_StackOverflow中文版Initial Catalog=AtentoMIG;Integrated Security=True" />
</connectionStrings>
<system.web>
    <!-- 
        Set compilation debug="true" to insert debugging 
        symbols into the compiled page. Because this 
        affects performance, set this value to true only 
        during development.
    -->
    <compilation debug="true" targetFramework="4.0">
        <assemblies>
            <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
    <!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->
    <authentication mode="Forms">
        <forms loginUrl="login.aspx" name=".ASPXFORMSAUTH"/>
    </authentication>
    <authorization>
        <deny users="?" />
    </authorization>
    <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
        <providers>
            <clear />
            <add
              name="SqlProvider"
              type="System.Web.Security.SqlMembershipProvider"
              connectionStringName="MySqlConnection"
              applicationName="MyApplication"
              enablePasswordRetrieval="false"
              enablePasswordReset="true"
              requiresQuestionAndAnswer="true"
              requiresUniqueEmail="true"
              passwordFormat="Hashed" />
        </providers>


ASP.Net has a built-in authentication system that stores user accounts in the aspnet_Users table.

You can create this table by running aspnet_regsql.exe from a Visual Studio command prompt.


You need to install/run the asp.net membership schema in the database you specify in the membership section of your web.config (MySqlConnection connection string in your case).

Take a look at this article for step by step instructions.


You have to use custom membership provider. Check out this video create custom membership provider Also article on code project about custom member ship


I think you need to read this article. http://msdn.microsoft.com/en-us/library/44w5aswa.aspx. This a good article to setup SAP.bet membership provider.


Your Login control doesn't have a button. Here's the code that's generated when you create a new web from Visual Studio:

    <asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false">
    <LayoutTemplate>
        <span class="failureNotification">
            <asp:Literal ID="FailureText" runat="server"></asp:Literal>
        </span>
        <asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification" 
             ValidationGroup="LoginUserValidationGroup"/>
        <div class="accountInfo">
            <fieldset class="login">
                <legend>Account Information</legend>
                <p>
                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>
                    <asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" 
                         CssClass="failureNotification" ErrorMessage="User Name is required." ToolTip="User Name is required." 
                         ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
                </p>
                <p>
                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                    <asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" 
                         CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Password is required." 
                         ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
                </p>
                <p>
                    <asp:CheckBox ID="RememberMe" runat="server"/>
                    <asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe" CssClass="inline">Keep me logged in</asp:Label>
                </p>
            </fieldset>
            <p class="submitButton">
                <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="LoginUserValidationGroup"/>
            </p>
        </div>
    </LayoutTemplate>
</asp:Login>

If membership is set up correctly, setting the button's CommandName to Login should contact the membership provider and call all the necessary methods validate the user in the database.


I'm not sure exactly what you mean about binding the username and password. But there really shouldn't be any need to do any binding.

The authentication controls will work right out of the box assuming that you have a valid membership provider configured.

The control itself isn't tied to any particular implemention, it just expects to find a provider that has the ability to do what a valid membership provider needs to do.

By default the SqlMembershipProvider is the default provider (assuming you didn't change your machine.config file). But you have the ability to swap out providers. So when microsoft says you don't need to do anything to use the control, they are correct, assuming you want to use the sql membership provider.

In fact by default throw a login control on a page, and load the page, if the database doesn't exist, a sql express database will put into your app_data folder. At least that's the way it's supposed to work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号