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