【发布时间】:2011-07-22 15:55:32
【问题描述】:
我有一个关于asp.net 的登录控制的问题。我在我的应用程序中定义了 asp.Login 和密码,还使用设置身份验证所需的信息在 Web 配置中进行了更改,但我想知道如何将用户和密码字段绑定到数据库:我有这个疑问是因为在 msdn 文档中说"If you use the Login control with ASP.NET membership, you do not need to write code to perform authentication."。
这是我的观点的代码
<%@ 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>
还有我的 Web.Config
<appSettings/>
<connectionStrings>
<add name="MySqlConnection" connectionString="Data Source=.\SqlExpress;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 中引用
System.Windows.Forms.dll。你会后悔的。
标签: c# asp.net login-control