Debugging IIS 7.5 FTP Custom Authentication Provider
A customers need was to have quickly an ftp server to share large files with some third party. The security restrictrions in our company need a two-factor autentication.
So I had the idea to create a custom authentication provider where the user can provider his password and token in the ftp password field like password#token.
In this post I will not explain how you create a custom authetication provider. This is explained very well on the links I'll post.
I found this great blog post of Robert MyMurray where he describes how to create a custom provider with multiple examples. I followed his steps and realized that I couldn't debug the code I wrote with Visual Studio.
Then I found this post on iis.net, which finally helped me to debug my code.
So I had the idea to create a custom authentication provider where the user can provider his password and token in the ftp password field like password#token.
In this post I will not explain how you create a custom authetication provider. This is explained very well on the links I'll post.
I found this great blog post of Robert MyMurray where he describes how to create a custom provider with multiple examples. I followed his steps and realized that I couldn't debug the code I wrote with Visual Studio.
Then I found this post on iis.net, which finally helped me to debug my code.
Steps to debug:
I assume that:- You already created a solution and implemeted one of the examples of Rober McMurray or your own one.
- You signed your dll and deployed it to your Global Assembly Cache
- You installed and configured a ftp site on your IIS
- You registered your provider. This is little bit tricky. There is no check when you register your provider. Please be sure to enter the correct format:
Namespace.Classname,DLL Name,Version,Culture,PublixKeyToken
(e.g FTP.Authentication.FtpLdapAuthentication,FTP.Authentication,Version=1.0.0.0,Culture=neutral,PublicKeyToken=e1729a8537bc265b)
You must register the provider on server level not on site. - You changed the FTP Authentication Provider to your custom one.
1.) Load Process
First you have to start the process which loads your assembly. Go to your ftp server open a dos command prompt and type:
C:\>ftp localhost
C:\>ftp localhost
Now type something. If your login was unsuccessful type quit
ftp>quit.
Now the ftp service must have loaded your assembly if you registered it correctly. Type now following command into the dos command to find the process id of the process which loaded your assembly.
C:\>tasklist /M <Name of your dll>.dll
Now attach your Visual Studio to the process. Open Visual Studio > Debug > Attach to process and select the process dllhost.exe with the found PID:
Now set a breakpoint somewhere in your AuthenticateUser method. Somehow the initialize method is called prior.
Now type again in your command prompt:
C:\>ftp localhost
Enter your crendetials. Now the debugger should popup.
2.) Deploy a new dll
If you changed your code and build a new dll and you want to debug it, you have to kill the process whic hosts your dll.
Follow these steps to deploy and debug a new dll
- Quit the ftp prompt with "quit"
- Kill the process with:
- C:\>taskkill /pid 12308 /f
- stop the ftpserver with :
- C:\>net stop ftpsvc
- Browse to C:\Windows\assembly
- Right click on your assembly and uninstall
- Move your new assembly to C:\windows\assembly (You cant copy you have to drag it with your mouse or gacutil tool)
- Start your ftp server
- C:\>net start ftpsvc
- Login to your ftp server and enter some crendentials
- C:\>ftp localhost
- Quit the ftp server
- Find the Process ID (PID) of the dllhost:
- C:\>tasklist /M <your dll name>.dll
- Attach to the new dllhost.exe
- Login to your ftp server again
Comments
Thanks for sharing this information ,looking forward for more posts like this .
Sharepoint Developers