Welcome

首页 / 软件开发 / .NET编程技术 / 安全简报: 受限用户问题和分持机密

安全简报: 受限用户问题和分持机密2011-10-24 msdn Keith Brown本月我将回答更多的读者问题。我将讨论在普通用户帐户下运行的 Windows Communication Foundation Web 服务以及使用分持机密技术和双重密钥控制来保护信用卡数据等问题。

问:当我 以非管理员的身份运行简单的 Windows® Communication Foundation 服务时,为何无法启动?

答:首先我想说的是,很高兴听到您在普通用户帐户下测试代码!这是开发人员不应 忽略的测试工作的一个重要方面。

现在,对于那些想彻底查清此类问题的 用户,我推荐的第一个方法是启动 Filemon 和 Regmon,查找文件打开操作失败的记录或查找注册表项, 这两个工具可以从 Sysinternals(最近被 Microsoft 收购)的网站 www.sysinternals.com 获得。遗憾 的是,这些工具不能诊断所有可能导致此问题的症结所在。即使在 Windows Communication Foundation 中实施的侦听 HTTP 通道这类最简单的 Web 服务,默认情况下,也不能以普通用户身份来运行,除非 Windows Communication Foundation 以 IIS 作为宿主。这是因为 Windows Communication Foundation HTTP 通道使用 HTTP.SYS 驱动程序安装其侦听程序,而且 HTTP.SYS 不允许非管理员在没有管理员明确 授权的情况下,注册侦听程序。

为说明此问题,我构建了一个包含以下两个文件的简单 Web 服务 :该服务的源文件和应用程序配置文件。图 1 显示了该服务的代码。在您以管理员身份启动该服务时, 一切正常。但以普通用户身份运行该服务时,则出现大问题!图 2 显示了在使用 Microsoft® .NET Framework 3.0 Beta 2 版时发生的异常情况。

Figure 2 Exception When Run as Normal User

System.ServiceModel.Diagnostics.CallbackException: A user callback threw an exception. Check the exception stack and inner exception to determine the callback that failed.---> System.NullReferenceException: Object reference not set to   an instance of an object.  at System.ServiceModel.Channels.DatagramChannelDemuxer`2.   OnListenerClosed(Object source, EventArgs args)  at System.ServiceModel.Channels.CommunicationObject.OnClosed()  --- End of inner exception stack trace ---  at System.ServiceModel.Channels.CommunicationObject.OnClosed()  at System.ServiceModel.Channels.CommunicationObject.Abort()  at System.ServiceModel.Channels.ChannelListenerBase.OnAbort()  at System.ServiceModel.Channels.SecurityChannelListener`1.OnAbort()  at System.ServiceModel.Channels.CommunicationObject.Abort()  at System.ServiceModel.Channels.ChannelListenerBase.OnAbort()  at System.ServiceModel.Channels.CommunicationObject.Abort()  at System.ServiceModel.Dispatcher.ChannelDispatcher.OnAbort()  at System.ServiceModel.Channels.CommunicationObject.Abort()  at System.ServiceModel.ServiceHostBase.OnAbort()  at System.ServiceModel.Channels.CommunicationObject.Abort()  at System.ServiceModel.Channels.CommunicationObject.Close(   TimeSpan timeout)  at System.ServiceModel.Channels.CommunicationObject.Close()  at System.ServiceModel.Channels.CommunicationObject.Dispose()  at Program.Main(String[] args) in   C:workHelloServiceProgram.cs:line 24