2016-04-25 44 views
0

我正在构建一个自定义IIS FTP身份验证程序,旨在从SQL Server表进行身份验证。该表具有用户名,密码和主目录,这些从查询中返回。所有这些在验证器中似乎都能正常工作,但是当我尝试实现主目录提供程序时,我永远不会进入我指定的文件夹 - 它似乎并未实际调用提供程序。同样,如果我尝试实施后处理来提供上传文件的自定义处理,那也不会触发。我很难过,因为我想我已经正确地注册了一切,或者验证方法不会运行 - 那么为什么其他两个都不能执行?IIS FTP 8主目录提供程序不会触发

我已经缩小了我的代码,以便我只是写入一个文本文件,以便我可以判断方法是否正在触发。身份验证起作用,其他则不起作用。

using System; 
using System.IO; 
using Microsoft.Web.FtpServer; 

namespace MyCustomFtpExtension 
{ 
    public class DatabaseAuthenticator : BaseProvider, 
     IFtpAuthenticationProvider, 
     IFtpRoleProvider, IFtpHomeDirectoryProvider, IFtpPostprocessProvider, 
     IFtpLogProvider 
    { 
     private readonly string _logfile = Path.Combine(@"c:\test", "logs", "FtpExtension.log"); 
     public bool AuthenticateUser(string sessionId, string siteName, string userName, string userPassword, 
      out string canonicalUserName) 
     { 
      canonicalUserName = userName; 

      var result = DatabaseHelper.Authenticate(userName, userPassword); 
      if (result) 
      { 
       LogMessage("Login Success: " + userName); //this message appears 
      } 
      else 
      { 
       LogMessage("Login Failure: " + userName); 
      } 
      return result; 
     } 

     string IFtpHomeDirectoryProvider.GetUserHomeDirectoryData(
      string sessionId, 
      string siteName, 
      string userName) 
     { 
      LogMessage("In ftp home directory"); //this message never appears 

      return @"c:\temp\test"; 
     } 

     public FtpProcessStatus HandlePostprocess(FtpPostprocessParameters postProcessParameters) 
     { 

      LogMessage("Running Post Process"); //this message never appears 
      return FtpProcessStatus.FtpProcessContinue; 
     } 

     public bool IsUserInRole(string sessionId, string siteName, string userName, string userRole) 
     { 
      return true; // I don't care about this - if they authenticate, that's all I need. 
     } 


     //to keep the sample short I took out the log provider - it was copy/paste from Microsoft's example 

     //this is a quick and dirty output so I can see what's going on (which isn't much) 
     private void LogMessage(string logEntry) 
     { 
      using (var sw = new StreamWriter(_logfile, true)) 
      { 
       // Retrieve the current date and time for the log entry. 
       var dt = DateTime.Now; 

       sw.WriteLine("{0}\t{1}\tMESSAGE:{2}", 
        dt.ToShortDateString(), 
        dt.ToLongTimeString(), 
        logEntry); 
       sw.Flush(); 
      } 
     } 
    } 
} 

回答

0

我在FTP授权规则下的IIS管理器中发现了一个我没有注意到的设置。我不得不改变那里的设置来表示我的自定义组件。一旦我这样做了,所有的方法都被解雇了,我在我的文本文件中看到了所有的消息,现在我又有了一个错误。所以回到研究我去。但这就是他们没有开枪的原因。