어떻게 Windows 인증이 작동하는지 이해하고 구현하는 방법을 이해하려고합니다. 필자는 꽤 많은 기사를 읽고 유튜브에서 아주 짧은 길이의 비디오를 보았지만 제대로 작동하려면 내 web.config 파일/index.aspx 페이지에 추가해야 할 내용을 고집하지 않아도됩니다. 여기 asp.net에서 windows 인증을 사용하여 C#
는 index.aspx 페이지입니다 :using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
namespace asset_management_system
{
public partial class index1 : System.Web.UI.Page
{
DataAccessLayer dal = new DataAccessLayer();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void loginBut_Click(object sender, EventArgs e)
{
string username = usernameTB.Text.Trim();
string password = passwordTB.Text.Trim();
try
{
using (SqlDataReader dr = dal.CheckLoginDetails(username))
{
//if username does not exist
if (!dr.Read())
{
MessageBox.Show("Invalid login details");
}
else
{
//if password matches the username then redirect to home page
if (dr[0].ToString() == password)
{
Session["username"] = username;
Response.Redirect("Home/home.aspx");
}
else
{
MessageBox.Show("Invalid login details");
}
}
}
}
catch (SqlException sqlex) { MessageBox.Show("There may be an issue with the server, please contact the administrator" +
" and provide this error message: " + sqlex); }
catch (Exception ex) { MessageBox.Show("error message: " + ex); }
}//end of loginBut_click method
}//end of class
}//end of namespace
그리고 여기 web.config 파일
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="Asset management System DBConnectionString" connectionString="Data Source=STEPHENP\SQLEXPRESS;Initial Catalog="Asset management System DB";Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<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>
<authentication mode="Windows">
</authentication>
<identity impersonate="true"/>
</system.web>
</configuration>
'인증'요소를 사용하여 위치를 잠글 필요가 있습니다. –
당신은 데이터베이스에 대해 사용자 이름과 암호를 검사하고 있습니다. 그보다 폼 기반 인증에 가깝습니다. Windows 인증의 목적은 그럴 필요가 없거나 Windows가 필요한 경우 인증은 로그인 페이지에 액세스 할 수있는 사람을 잠급니다. web.config에 authentication 요소를 올바르게 배치했지만 인증 요소가 누락되었습니다. 이 페이지 및 이해를 참조하십시오. http://msdn.microsoft.com/en-us/library/8d82143t(v=vs.85).aspx – Bearcat9425
감사합니다.이 줄을 web.config 파일에 추가했습니다. authorization> 내 index.aspx 페이지에 추가해야하는 코드가 있습니까? –