ASP.Net MVC 控制器操作与 ASP.Net Web 表单之间的模拟有区别吗?在同一个 Web 项目中使用完全相同的代码,当从 Web 窗体连接到 SQL Server 时,我能够成功地模拟 Windows 用户,但不能从控制器操作。这是我正在测试的代码示例:
string sqlQuery = @"SELECT Top 10 FullName FROM Customer";
// Connect to the database server. You must use Windows Authentication;
SqlConnection connection = new SqlConnection("Data Source=ServerName;Initial Catalog=DBName;Integrated Security=SSPI");
// Create a DataTable to store the results of the query.
DataTable table = new DataTable();
// Create and configure the SQL Data Adapter that will fill the DataTable.
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(sqlQuery, connection);
// Execute the query by filling the DataTable.
adapter.Fill(table);
我已经检查了控制器和 Web 表单上的 HttpContext 用户,它们看起来相同。但是,在运行 SQL 跟踪时,控制器操作始终作为网络服务运行,而 Web 表单作为用户运行。任何关于为什么这两个行为不同以及如何在控制器操作中模拟的澄清将不胜感激。