asp.net - 模拟:ASP.Net MVC Controller 操作与Web窗体

标签 asp.net asp.net-mvc webforms impersonation sqlconnection

ASP.Net MVC Controller 操作与ASP.Net Web窗体之间的模拟是否有区别?在同一Web项目中使用完全相同的代码,当从Web窗体而不是从Controller Action连接到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);

我已经检查了 Controller 和Web窗体上的HttpContext用户,它们看起来相同。但是,在运行SQL跟踪时, Controller 操作始终作为网络服务运行,而Web表单以用户身份运行。关于这两个为什么表现不同以及如何在 Controller Action 中模拟的任何澄清都将受到赞赏。

最佳答案

尝试添加

 <identity impersonate="true">


<system.web>

适用于mvc应用的web.config文件的一部分

关于asp.net - 模拟:ASP.Net MVC Controller 操作与Web窗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1909114/

相关文章:

c# - 在 ASP.NET MVC 的参数中编码非 UTF-8 文本

asp.net - 从 .aspx 文件自动生成代码隐藏文件

css - HTML 未按预期呈现

c# - CS1061 : Compilation Error Message

c# - 如何在 Page_Load 获取用户本地时间

c# - Jquery ui 对话框触发多个对话框问题

javascript - 使用 ajax 回复博客文章评论

asp.net - Internet Explorer 8 实际浏览器中的 CSS 问题

c# - MetadataType 属性在自定义验证器中被忽略

c# - 如何生成 24 小时后过期的唯一 token ?