2016-04-25 472 views
0

我已经使用C#为IIS FTP 8创建了自定义身份验证器。我已正确设置自定义功能的处理器,这样IIS使用我的DLL,但是当我尝试登录我总是得到:IIS FTP 8自定义身份验证授权规则拒绝访问

Response: 331 Password required 
Command: PASS ******** 
Response: 530-User cannot log in, home directory inaccessible. 
Response: Win32 error: No such interface supported 
Response: Error details: Authorization rules denied the access. 
Response: 530 End 

我敢肯定,我已经排除了文件夹的权限 - 这是敞开的因为它可以。所以,据我了解的信息 - 它告诉我,我没有任何授权规则。但似乎没有办法为自定义身份验证器添加一个。 IIS管理器中的用户界面屏蔽了常规设置功能,因此您无法在其中添加任何设置。

我试过应用CMD:

appcmd.exe set config "mysite" -section:system.ftpServer/security/authorization /+"[accessType='Allow',roles='administrators',permissions='Read, Write']" /commit:apphost 

与作用(客人,*等)没有成功的变化。

我试图编辑在的applicationHost.config网站的入口,但我找不到在哪里把它放在其他比这个“非定制”的例子来自微软的文档的任何文件:

<location path="ftp.example.com"> 
    <system.ftpServer> 
    <security> 
     <authorization> 
     <add accessType="Allow" roles="administrators" permissions="Read, Write" /> 
     </authorization> 

当我在我的配置中的指定位置添加授权标签,FTP服务将不会重新启动。

那么,当您使用自定义FTP身份验证提供程序时,您如何添加授权规则?

为了完整起见,以下是提供者类的代码。请注意输出到LogMessage方法中的文本文件。这就告诉我,一切正常 - 它不能到达用户的主文件夹,因为它没有授权规则。

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

您需要运行命令来分配库fir主目录提供程序。

AppCmd set site "FTP Site Name" /+ftpServer.customFeatures.providers.[name='CustomFtpAuthDemo',enabled='true']