我有一个使用Windows身份验证的现有ASP.NET报告应用程序。 很多报告生成代码都在单独的类中,并且有一个我没有写入的核心错误记录器,我相信这个错误记录器是为Windows应用程序构建的,因为它使用WindowsIdentity.GetCurrent()。Name。 在ASP.NET的情况下,我相信这将返回在服务器上运行ASP.NET页面的帐户。
我相信在页面上使用User.Identity.Name将是正确的方式,但它不能从仅在页面上的报告生成类中提供。 有没有办法使用错误记录器类来获取它,而不将它作为一个额外的参数传递。
有数百个报告类,所以我害怕必须通过并为每一个添加一个参数。
I have an Existing ASP.NET reporting application using windows authentication. A lot of the report generation code is in separate classes and has a core error logger that I didn't write, this error logger I believe was built for windows apps as it uses WindowsIdentity.GetCurrent().Name. In the case of ASP.NET I believe this will return the account running the ASP.NET pages at the server.
I believe using User.Identity.Name on the pages would be the correct way to do this but it is not available from within the report generation classes only on the page. Is there a way to obtain it withing the error logger class without passing it as an extra parameter.
There are hundreds of report classes so I dread to have to go through and add a parameter to every one.
最满意答案
如果你可以在你的web.config中使用模拟:
.... <authentication mode="Windows"/> <identity impersonate="true"/> ....您的报告课程将获得正确的用户。
如果您的报告类可以引用System.Web程序集并且您愿意修改代码,则还可以执行以下操作:
HttpContext.Current.User.Identity.Name但要确保调用者来自ASP.NET请求,否则会抛出一个nullref。
If you can use impersonation in your web.config:
.... <authentication mode="Windows"/> <identity impersonate="true"/> ....your report classes will get the right user.
If your reporting classes can reference the System.Web assembly and you are willing modify the code, you could also do:
HttpContext.Current.User.Identity.Namebut make sure the caller comes from an ASP.NET request or it will throw a nullref.
更多推荐
ASP,NET,Name,报告,电脑培训,计算机培训,IT培训"/> <meta name="description&q
发布评论