2017-10-06 43 views
0

在Windows 2012 R2上的IIS中將控制檯應用程序作爲CGI運行。iis控制檯應用程序目錄條目searchresult

在連接到活動目錄(AD),使用的DirectoryEntry,參考: lccDEDirectoryEntry =新的DirectoryEntry(lccSDomainConnectionString,lccSUserId,lccSUserPassword,lccATAuthTypes);

然後使用DirectorySearcher,ref: lccDSSearcher = new DirectorySearcher(lccDEDirectoryEntry);

然後查找所有匹配的對象,ref: lccSRCResults = lccDSSearcher.FindAll();

後來終於在訪問搜索結果,參考: 的foreach(信息搜索結果lccSRResultLoop在lccSRCResults)

一切工作正常,直到我試圖訪問搜索結果,它拋出一個「非法字符路徑」。

我可以在命令窗口中託管IIS的服務器上直接運行相同的控制檯應用程序,並且工作正常,包括訪問/顯示SearchResults。也適用於Windows 7工作站/等。

一年前,我打了一個相同類型的問題,調用了HttpUtility,它最終成爲IIS中的一個錯誤,它正在尋找一個空配置設置。 Microsoft提供了一個修復程序以使用此行: AppDomain.CurrentDomain.SetData(「APP_CONFIG_FILE」,Environment.CurrentDirectory +「\」+ System.AppDomain.CurrentDomain.FriendlyName +「.config」);

每本博客頁面: http://www.dreamincode.net/forums/topic/300197-webrequest-in-a-cgi

這解決了零配置設置在一年前,當你運行HttpUtility,IIS會尋找一個「APP_CONFIG_FILE」的設置,作爲一個控制檯應用程序運行時,未設置並沒有使用。

那麼,我的調試/等。已經顯示出同樣的問題,即設置爲空,因此函數「CheckIllegalCharacters」不會崩潰,因爲它無法解析空值。

不幸的是,我找不到它正在尋找的設置。我甚至列舉了所有的AppSetting鍵,參考: https://msdn.microsoft.com/en-us/library/system.appdomain.getdata%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

並讓我的代碼填充每個虛擬值,但是,沒有去。

關於如何找到缺少的設置鍵名稱的任何線索?還是其他解決方案

這裏是堆棧跟蹤。底部是我的函數'lccLDAP',它通過調用SearchResults循環來啓動其餘部分。

堆棧跟蹤 在System.Security.Permissions.FileIOPermission.CheckIllegalCharacters(字符串[] STR,布爾onlyCheckExtras) 在System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess訪問,AccessControlActions控制,字符串[] pathListOrig,布爾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(字符串applicationFilename,裝配exeAssembly,布爾isHttp) 在System.Configuration.ClientConfigPaths..ctor(字符串exePath,布爾includeUserConfig) 在System.Configuration.ClientConfigPaths.GetPaths(字符串exePath,布爾includeUserConfig) 在System.Configuration。 ClientConfigurationHost.RequireCompleteInit(IInternalConfigRecord記錄) 在System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey,布爾getLkg,布爾的checkPermission,布爾getRuntimeObject,布爾requestIsHere,對象&結果,對象& resultRuntimeObject) 在System.Configuration.BaseConfigurationRecord.GetSection( String configKey) at System.Configuration.ConfigurationManager.GetSection(String sectionName) 在System.Configuration.PrivilegedConfigurationManager.GetSection(字符串sectionName) 在System.DirectoryServices.SearchResultCollection.ResultsEnumerator..ctor(SearchResultCollection結果,字符串parentUserName,字符串parentPassword,AuthenticationTypes parentAuthenticationType) 在System.DirectoryServices.SearchResultCollection.get_InnerList() 在System.DirectoryServices.SearchResultCollection.get_Item(的Int32索引) 在lccCoreFunctionsClass.lccLDAP(lccSettingsClass lccParamSCSettings,的Int32 lccLDAPId,的Int32 lccIFlag,字符串lccSParam)

+0

您可以嘗試使用反射器來調試內部ms .net代碼, G。點窺視。爲控制檯應用程序工作,應爲iis工作 – oldovets

+0

感謝您的建議。由於IIS運行在單個服務(dll)中,並且啓動了內部應用程序池,因此如何將反射器連接到在單個IIS服務中的應用程序池內啓動的特定控制檯應用程序? –

+0

我對IIS不熟悉,但從我的理解中,當您點擊瀏覽器中的鏈接時,IIS將運行您的過程。所以你應該在進程樹中找到它,並且當然可以使用visual studio和thread.sleep來附加它。反射器用作符號服務器。當進程加載這個dll時,它爲內部.net庫創建pdb文件。最後,pdb將被加載到visual studio中,因此您將能夠在調試過程中進入ms代碼 – oldovets

回答

0

添加什麼,我終於做到了。由於我的控制檯應用程序在IIS服務器上運行良好,只是沒有通過Directory.SearchResults的IIS,我將程序拆分爲在前端和後端模式下運行。前端服務器IIS網頁,並將請求傳遞給後端以完成LDAP任務。後端然後服務於前端的響應。無論如何,良好的三線安全。以防其他人尋找可能的解決方案。

相關問題