简体   繁体   English

iis控制台应用程序目录条目搜索结果

[英]iis console application directoryentry searchresult

Running a Console Application as a CGI in IIS on Windows 2012 R2. 在Windows 2012 R2上的IIS中将控制台应用程序作为CGI运行。

On connection to Active Directory (AD), using DirectoryEntry, ref: lccDEDirectoryEntry = new DirectoryEntry(lccSDomainConnectionString, lccSUserId, lccSUserPassword, lccATAuthTypes); 使用DirectoryEntry连接到Active Directory(AD)时,请参考:lccDEDirectoryEntry = new DirectoryEntry(lccSmainConnectionString,lccSUserId,lccSUserPassword,lccATAuthTypes);

Then using DirectorySearcher, ref: lccDSSearcher = new DirectorySearcher(lccDEDirectoryEntry); 然后使用DirectorySearcher,请参考:lccDSSearcher = new DirectorySearcher(lccDEDirectoryEntry);

Then finding all matching objects, ref: lccSRCResults = lccDSSearcher.FindAll(); 然后找到所有匹配的对象,请参见:lccSRCResults = lccDSSearcher.FindAll();

Then finally accessing the search results, ref: foreach (SearchResult lccSRResultLoop in lccSRCResults) 然后最终访问搜索结果,请参考:foreach(lccSRCResults中的SearchResult lccSRResultLoop)

All works fine, until I try to access the Search Results, it throws an "Illegal Characters In Path". 一切正常,直到我尝试访问搜索结果之前,它都会引发“路径中的非法字符”。

I can run the same Console Application directly on the server hosting the IIS in a command window and it works fine, including accessing/displaying the SearchResults. 我可以在命令窗口中直接在托管IIS的服务器上运行相同的控制台应用程序,它可以正常工作,包括访问/显示SearchResults。 Also works fine on Windows 7 workstation/etc. 在Windows 7工作站/等上也可以正常工作。

I hit this same type issue a year ago with a call to HttpUtility, and it ended up being a bug in IIS where it is looking for a configuration setting that is null. 一年前,我通过调用HttpUtility遇到了同一类型的问题,但最终成为IIS中的一个错误,正在该错误中寻找配置设置为null。 Microsoft supplied a fix to use this line: AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", Environment.CurrentDirectory + "\\" + System.AppDomain.CurrentDomain.FriendlyName + ".config"); Microsoft提供了使用此行的修补程序:AppDomain.CurrentDomain.SetData(“ APP_CONFIG_FILE”,Environment.CurrentDirectory +“ \\” + System.AppDomain.CurrentDomain.FriendlyName +“ .config”);

Per this blog page: http://www.dreamincode.net/forums/topic/300197-webrequest-in-a-cgi 在此博客页面上: http : //www.dreamincode.net/forums/topic/300197-webrequest-in-a-cgi

And that solved the null configuration setting a year ago, as when you run HttpUtility, IIS looks for an "APP_CONFIG_FILE" setting that is not set when running as a Console Application and isn't used. 一年前,这解决了空配置设置,因为当您运行HttpUtility时,IIS查找一个“ APP_CONFIG_FILE”设置,该设置在作为控制台应用程序运行时未设置并且未被使用。

Well, my debugging/etc. 好吧,我的调试/等。 has shown that the same issue being hit, ie a setting is null and so the function "CheckIllegalCharacters" isn't crashing as it can't parse a null value. 已经显示出遇到相同的问题,即设置为null,因此“ CheckIllegalCharacters”函数不会崩溃,因为它无法解析null值。

Unfortunately, I cannot locate the setting it is looking for. 不幸的是,我找不到所需的设置。 I even enumerated through all AppSetting keys, ref: https://msdn.microsoft.com/en-us/library/system.appdomain.getdata%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 我什至列举了所有AppSetting键,例如: https ://msdn.microsoft.com/zh-cn/library/system.appdomain.getdata%28v=vs.110%29.aspx?f = 255&MSPPError = -2147217396

And have my code filling each one in with a dummy value, but, no go. 并让我的代码用一个虚拟值填充每个代码,但是不行。

Any clue on how to find the missing setting key name? 关于如何找到丢失的设置键名称的任何线索? Or other solution? 还是其他解决方案?

Here is the Stack Trace. 这是堆栈跟踪。 At the bottom is my function 'lccLDAP', which initiates the rest by calling the SearchResults loop. 最下面的是我的函数“ lccLDAP”,它通过调用SearchResults循环来初始化其余的函数。

STACK TRACE at System.Security.Permissions.FileIOPermission.CheckIllegalCharacters(String[] str, Boolean onlyCheckExtras) at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path) at System.Reflection.RuntimeModule.get_FullyQualifiedName() at System.Configuration.ClientConfigPaths.SetNamesAndVersion(String applicationFilename, Assembly exeAssembly, Boolean isHttp) at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig) at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig) at System.Configuration.ClientConfigurationHost.RequireCompleteInit(IInternalConfigRecord record) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean System.Security.Permissions.FileIOPermission.CheckIllegalCharacters(String [] str,Boolean onlyCheckExtras)处的STACK TRACE,位于System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess访问,AccessControlActions控件,String [] pathListOrig,布尔值checkForDuplicates,布尔值needFullPath,布尔值System.Security.Permissions.FileIOPermission..ctor处的copyPathList).ctor(System.Configuration.ClientConfigPaths.SetNamesAndVersion(String applicationFilename,Assembly exeAssembly,Boolean isHttp)处的System.Reflection.RuntimeModule.get_FullyQualifiedName()处的FileIOPermission.ctor(FileIOPermissionAccess访问,字符串路径) .Configuration.ClientConfigPaths..ctor(System.Configuration.ClientConfigPaths.GetPaths(String exePath,Boolean includeUserConfig)在System.Configuration.ClientConfigurationHost.RequireCompleteInit(IInternalConfigRecord记录)在System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey,布尔 getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName) at System.DirectoryServices.SearchResultCollection.ResultsEnumerator..ctor(SearchResultCollection results, String parentUserName, String parentPassword, AuthenticationTypes parentAuthenticationType) at System.DirectoryServices.SearchResultCollection.get_InnerList() at System.DirectoryServices.SearchResultCollection.get_Item(Int32 index) at lccCoreFunctionsClass.lccLDAP(lccSettingsClass lccParamSCSettings, Int32 lccLDAPId, Int32 lccIFlag, String lccSParam) getLkg,Boolean checkPermission,Boolean getRuntimeObject,Boolean requestIsHere,Object&result,Object&resultRuntimeObject在System.Configuration.ConfigurationManager.GetSection(String configKey)在System.Configuration.ConfigurationManager.GetSection(String sectionName)在System.Configuration.PrivilegedConfigurationManager.GetSection( System.DirectoryServices.SearchResultCollection.ResultsEnumerator..ctor处的String sectionName)(System.DirectoryServices.SearchResultCollection.get_InnerList()处System.DirectoryServices.SearchResultCollection.get_Item(Int32 index)处的SearchResultCollection results,String parentUserName,String parentPassword,AuthenticationTypes parentAuthenticationType) lccCoreFunctionsClass.lccLDAP(lccSettingsClass lccParamSCSettings,Int32 lccLDAPId,Int32 lccIFlag,字符串lccSParam)

Adding what I finally did. 加上我终于做了。 Since my console app runs fine on the IIS server, just not through IIS for Directory.SearchResults, I split the program to run in front-end and back-end modes. 由于我的控制台应用程序在IIS服务器上运行良好,而不是通过IIS for Directory.SearchResults运行,因此我将程序拆分为以前端和后端模式运行。 The front-end servers IIS web pages, and passes requests to the back-end for LDAP tasks. 前端服务器IIS网页,并将请求传递给后端以执行LDAP任务。 The back-end then serves responses to the front-end. 然后,后端为前端提供响应。 Good tier-3 security anyway. 无论如何,良好的三层安全性。 Just in case others look for a possible solution. 以防万一其他人寻找可能的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM