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.

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

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
  1. Quit the ftp prompt with "quit"
  2. Kill the process with: 
    1. C:\>taskkill /pid 12308 /f
  3. stop the ftpserver with :
    1. C:\>net stop ftpsvc
  4. Browse to C:\Windows\assembly
  5. Right click on your assembly and uninstall
  6. Move your new assembly to C:\windows\assembly (You cant copy you have to drag it with your mouse or gacutil tool)
  7. Start your ftp server
    1. C:\>net start ftpsvc
  8. Login to your ftp server and enter some crendentials
    1. C:\>ftp localhost
  9. Quit the ftp server
  10. Find the Process ID (PID) of the dllhost:
    1. C:\>tasklist /M <your dll name>.dll
  11. Attach to the new dllhost.exe
  12. Login to your ftp server again


Sources:




Comments

Unknown said…
Hi Baris ,

Thanks for sharing this information ,looking forward for more posts like this .






Sharepoint Developers

Popular posts from this blog

Ways to redirect http requests in SharePoint

Open SharePoint 2010/2013 Display, Edit, New Forms in Modal Dialogs

How to create a FAQ in SharePoint with OOB features