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