Access データベースで Visual Studio のログイン コントロールを使用しようとしています。2つの使い方がよくわかりません。これが私がこれまでに持っているものです:
ログイン.aspx:
<%@ Page Title="Login" Language="C#" MasterPageFile="~/EditSite.master" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Login ID="Login1" runat="server">
</asp:Login>
</asp:Content>
コードビハインドは次のとおりです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;
using System.Data.OleDb;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
ViewState["LoginErrors"] = 0;
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
if (YourValidationFunction(Login1.UserName, Login1.Password))
{
e.Authenticated = true;
Login1.TitleText = "Successfully Logged In";
} else {
e.Authenticated = false;
}
}
protected void Login1_LoginError(object sender, EventArgs e)
{
if (ViewState["LoginErrors"] == null)
ViewState["LoginErrors"] = 0;
int ErrorCount = (int)ViewState["LoginErrors"] + 1;
ViewState["LoginErrors"] = ErrorCount;
if ((ErrorCount > 3) && (Login1.PasswordRecoveryUrl != string.Empty))
Response.Redirect(Login1.PasswordRecoveryUrl);
}
private bool YourValidationFunction(string UserName, string Password)
{
bool boolReturnValue = false;
string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\TravelJoansDB.mdb;";
OleDbConnection con = new OleDbConnection(constr);
String SQLQuery = "SELECT UserName, Password FROM Login";
OleDbCommand com = new OleDbCommand(SQLQuery, con);
OleDbDataReader Dr;
con.Open();
Dr = com.ExecuteReader();
while (Dr.Read())
{
if ((UserName == Dr["UserName"].ToString()) & (Password == Dr["Password"].ToString()))
{
boolReturnValue = true;
}
Dr.Close();
return boolReturnValue;
}
return boolReturnValue;
}
}
ここにウェブ設定があります:
<configuration>
<configSections>
<section name="resizer" type="ImageResizer.ResizerSection" requirePermission="false" />
</configSections>
<system.web>
<customErrors mode="Off" />
<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>
<pages>
<controls>
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
</pages>
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
<providers>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</roleManager>
<!--
If you are deploying to a cloud environment that has multiple web server instances,
you should change session state mode from "InProc" to "Custom". In addition,
change the connection string named "DefaultConnection" to connect to an instance
of SQL Server (including SQL Azure and SQL Compact) instead of to SQL Server Express.
-->
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
<httpModules><add name="ImageResizingModule" type="ImageResizer.InterceptModule" /></httpModules></system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="AjaxControlToolkit" publicKeyToken="28f01b0e84b6d53e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.40412.0" newVersion="4.1.40412.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-TravelJoansBlog-20130718193109;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
<add name="TravelJoansDBSQLConnectionString" connectionString="Data Source=DCSLAPTOP\TRAVELJOANS;Initial Catalog=TravelJoansDBSQL;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
</modules>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
</system.webServer>
<resizer>
<plugins>
<add name="MvcRoutingShim" />
<add name="DiskCache" />
<add name="PrettyGifs" />
<add name="SimpleFilters" />
</plugins>
</resizer>
</configuration>
どんな助けでも大歓迎です。ログイン ボタンをクリックすると、ネットワーク関連のインスタンスが見つからないというエラーが表示されます。誰でも完全に制御できるように、フォルダーにセキュリティを設定しました。