我试图了解 Windows 身份验证的工作原理以及如何实现它。我已经阅读了很多文章并在 youtube 上观看了一些相当长的视频,但我仍然无法理解需要添加到我的 web.config 文件/index.aspx 页面以使其正常工作的内容。
这是 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>