问题描述
|
我试图将登录的用户名从我的网络应用程序传递到Report Services。这是我的代码:
string usern = WindowsIdentity.GetCurrent().Name.ToString();
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl =
new Uri(@\"http://myserver/reportServer/\");
ReportViewer1.ServerReport.ReportPath = @\"/path/subpath/reportName\";
ReportParameter[] rp = new ReportParameter[1];
rp[0] = new ReportParameter(\"paramTest\",usern);
ReportViewer1.ServerReport.SetParameters(rp);
ReportViewer1.ServerReport.Refresh();
在本地运行时,一切正常,我可以在参数文本框中看到我的用户名。在服务器上运行它,我得到的是\“ NT AUTHORITY \\ NETWORK SERVICE \”而不是我的用户名。
有任何想法吗?提前致谢
解决方法
您的评论证实了我的怀疑-“ѭ1”是您在服务器上的Windows身份-这是应用程序池运行所使用的身份。
如果使用Windows身份验证,则以下三个链接可以帮助您获取应用程序用户的名称:
ASP.NET –在Windows身份验证下获取用户名
使用Windows身份验证获取Windows用户名
如何使用ASP.NET获取Window NT记录的用户名