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 フォームはユーザーとして実行されます。これら2つの動作が異なる理由と、コントローラーアクション内で偽装する方法についての説明をいただければ幸いです。