【问题标题】:IIS FTP 8 Home Directory Provider Won't FireIIS FTP 8 主目录提供程序不会触发
【发布时间】:2016-04-25 19:54:48
【问题描述】:

我正在构建一个自定义 IIS FTP 身份验证器,旨在从 SQL Server 表进行身份验证。该表具有用户名、密码和主目录,这些都是从查询中返回的。所有这些似乎在验证器中都可以正常工作,但是当我尝试实现主目录提供程序时,我从来没有进入我指定的文件夹 - 似乎实际上并没有调用提供程序。同样,如果我尝试实现一个后期处理来提供上传文件的自定义处理,那也不会触发。我很困惑,因为我认为我已经正确注册了所有内容,否则身份验证方法将无法运行 - 那么为什么其他两个不执行?

我已经缩减了我的代码,所以我只是写入一个文本文件,这样我就可以判断该方法是否正在触发。身份验证有效,其他则无效。

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();
            }
        }
    }
}

【问题讨论】:

    标签: c# iis ftp


    【解决方案1】:

    我在 IIS 管理器中的 FTP 授权规则下发现了一个我以前没有注意到的设置。我不得不更改那里的设置以指示我的自定义程序集。一旦我这样做了,所有的方法都被触发了,我在我的文本文件中看到了我的所有消息,现在我遇到了另一个错误。所以回到研究我去。但这就是他们没有开火的原因。

    【讨论】:

      猜你喜欢
      • 2010-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 2021-04-23
      • 2011-01-22
      相关资源
      最近更新 更多