当匿名用户调用Web服务时,无法将其写入事件日志 [英] Web service cannot write to Event Log when called by anonymous user

查看:58
本文介绍了当匿名用户调用Web服务时,无法将其写入事件日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要:如何配置Web服务,以便始终可以写入事件日志(与调用者无关)? 细节: 我有一个Web服务,它将一个条目写入应用程序日志.我通过一个小的控制台应用程序为此建立了事件源,我想我理解了这部分内容.在测试此WS时,我看到我已成功将条目写入事件日志.

SUMMARY: How to configure a web service such that writing to the Event Log is always possible (regardless of caller)? DETAILS: I have a web service which writes an entry to the Application Log. I established the event source for this by means of a little console application and I think I understand that part of things. When I test this WS, I see I am successfully writing my entry to the Event log.

承载此WS的虚拟目录确实不允许允许匿名访问,并且仅配置为Integrated Windows Auth.

The virtual directory which hosts this WS does NOT allow anonymous access and is configured for Integrated Windows Auth only.

我有一个调用此Web服务的Web客户端应用程序.当仅将Web客户端站点配置为仅用于Integrated Windows Auth时,对Web服务的调用将导致根据需要进行日志记录.

I have a web client application that calls this Webservice. When the web client site is configured for Integrated Windows Auth only, calls to the Webservice result in logging as desired.

但是,如果我将Web客户端站点更改为允许匿名访问,则Webservice尝试记录结果为InvalidOperationException.我忽略了它,但是无论如何调用它,都知道如何在Web服务中进行日志记录将是很高兴的.这是我的一些代码:

Yet, if I change the web client site to allow anonymous access then the Webservice attempt to log results in an InvalidOperationException. I ignore it but it would be nice to know how to get logging in the webservice regardless of how it is called. Here is a bit of my code:

   public FileService()
    {
        try
        {
            if (!EventLog.SourceExists(g_EventSource))
                EventLog.CreateEventSource(g_EventSource, g_EventLog);

            System.Security.Principal.WindowsIdentity UserIdentityInfo;
            UserIdentityInfo = System.Security.Principal.WindowsIdentity.GetCurrent();
            string AuthType = UserIdentityInfo.AuthenticationType;

    if (AuthType == "Kerberos")
    { engineWSE.Credentials = System.Net.CredentialCache.DefaultCredentials; }
    else
    { engineWSE.Credentials = new System.Net.NetworkCredential("u", "p", "domain"); }

    EventLog.WriteEntry(g_EventSource,
                "Caller: " + UserIdentityInfo.Name +
                " AuthType: " + UserIdentityInfo.AuthenticationType,
                EventLogEntryType.Information, 1);
        }
        catch (InvalidOperationException e)
        {
            // do nothing to ignore: "Cannot open log for source 'myAppSourceName'. You may not have write access." 
        }
    }

上面的构造函数中的示例在此有点人为设计(我主要是希望能够写出与Web服务中的错误相关的信息).

The example in the constructor above is sort of contrived for here (I am mainly interested in being able to write out info related to errors in the web service).

我希望有一种配置Web服务虚拟目录(或其中的代码)的方法,以便无论调用它的方式如何,都可以进行日志记录.

I hope there is a way to configure the web service virtual directory (or the code within) so that logging is possible regardless of how it got called.

推荐答案

您还应该检查您的web.config.

You should also check your web.config.

如果IIS设置为匿名,而web.config设置为Windows/模拟.然后将是试图写入事件日志的匿名IIS用户.

If IIS is set to anonymous and web.config is set to windows / impersonate. Then it will be the anonymous IIS user that is trying to write to the event log.

这篇关于当匿名用户调用Web服务时,无法将其写入事件日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆