Click here to Skip to main content
15,867,686 members
Articles / Web Development / IIS
Article

New Multisite DLL Or How to develop .NET project in a Root

Rate me:
Please Sign up or sign in to vote.
3.45/5 (12 votes)
8 Apr 20055 min read 96.5K   759   36   31
Utility to ease .NET development.

Introduction

How many times you probably wished that you can develop your .NET project in the root folder or host multiple websites on Win XP. If at least one time, then read on.

The problem with developing in the root is that VS does not really support that (although doable). Also, very often, I work on several projects or just simply would like to have a project in its own folder so that when I need I can easily bring it up for debugging/modifying without messing up all other projects.

Solution

I have come across multisite.dll (probably very well known) which allows to map different host names to different URLs. So I could setup www.project1.com to /project1 folder, www.project2.com to /project2 folder ... But this DLL does not work with .NET. The only thing it works well with is simple HTML, which basically makes it worthless.

But that made me wonder, what prevents it from working with .NET. After reading some documentation on ISAPI, I figured that the problem lies in how it handles the request.

When browser hits the IIS with http://www.project1.com/default.aspx, IIS converts the URL "/default.aspx" to physical path "C:\inetpub\wwwRoot\default.aspx". Only then that DLL gets its grip on the request and modifies physical path to the correct path "C:\inetpub\wwwRoot\project1\default.aspx". The first thing ASP.NET application does is, check for web.config and global.asax in the root folder and since the URL has not been changed the ASP.NET looks for those files in "\" folder and not in "\project1" folder, thus skipping to load config.asax or web.config making any serious project development with that version of Multisite.dll useless.

After I had realized that, I understood that the solution is to modify URL and not a physical path. After reading documentation more carefully, I discovered that SF_NOTIFY_PREPROC_HEADERS in conjunction with GetHeader, SetHeader will do exactly what I need.

  1. Browser hits the IIS with http://www.project1.com/default.aspx
  2. DLL modifies it to http://www.project1.com/project1/default.aspx.

Everything else is the same as if we would hit the URL http://www.project1.com/project1/default.aspx from the beginning. ASP.NET finds proper global.asax and web.config and works without even knowing that modification has been done.

Implementation of New Multisite DLL

  1. This step need to be done only once when you install my multisite.dll. Copy multisite.dll and config.ini in some folder then register it as ISAPI filter with IIS.
  2. Let's say you have .NET project. Let's say Project1. And you want it to be on www.mysite.com.
  3. Modify HOSTS file in C:\WINDOWS\system32\drivers\etc. Add a new line:
    127.0.0.1    www.mysite.com
    
  4. Modify config.ini in the same folder where mulitsite.dll is. Add a new line:
    mysite.com = /Project1
    

    Note, not www. Becasue www. will be stripped out automatically so it works as in real world.

  5. Restart IIS server. After that every time you hit http://www.mysite.com/mypage.aspx the URL will be converted to http://www.mysite.com/project1/mypage.aspx and everything will work. When you are done with the project, you simply need to copy everything to root folder of the production website. No modifications needed.

Important Notes

  1. Safely assume that your project is working from the root so that all images, css files, js files might be referenced from the root. No need to append the project name and then when moved to production rename all of them.
  2. Where possible use root "/" or "~" symbol of .NET in constructions like Response.Redirect("~/mypage.aspx") Or Response.Redirect("/mypage.aspx"). Do not use your project name. The construction Response.Redirect("~/mypage.aspx") will be translated to Response.Redirect("/project1/mypage.aspx"). Because of that multisite DLL will not modify the path. I.e., the path www.mysite.com/project1/mypage.aspx will not be touched and will be passed as is to IIS. (The key here is that first folder in URL matches mapping folder).
  3. In current implementation you need to restart IIS so that all changes in config.ini will be loaded.
  4. Debug is fully supported but because when you press F5 in Visual Studio, it opens http://localhost/.... You need to either map localhost to /Project1 or have a separate browser window point to http://www.mysite.com/.. and do all testing there. It's up to you which way to go but if you mapped localhost then do not forget to unmap it. Or you will not be able to access any other file on IIS outside of Project1 folder.
  5. It's crucial to have in config.ini the project folder to start with '/' symbol.
  6. Do not prefix names with www. in config.ini. www. is stripped out from the request to make it work like real web application. If you want both www. and non www. version of the working site, you need to add two lines to host file though. One for www. name and one without www. name!

Conclusion

I found that this small utility is very useful in my development work. I can keep all my projects running on my development machine and if needed easily be modified and uploaded on a production server. No need to run a "Replace ALL" to eliminate the project name.

Also it came very handy on my production server Ms.Piercing where I have multiple websites and instead of using the ability of IIS to run multiple instances of WWW, I am using my DLL to do that (it seems to me more lightweight).

If you have any questions about this DLL feel free to send me an email (remove nospam) or visit my website. I am planning to write next version which will not require to restart IIS every time you modify config.ini.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
I am a Senior Software developer who does a consulting work for several companies. Mostly it's an E-Commerce project.

I do have my own venture. Small online store my wife runs. Body Jewelry. Also visit Piercing info Cool thing is that nor I nor my wife has any piercings. My new website is Belly ring

Comments and Discussions

 
Question4.0 version Pin
Glay200924-Jan-13 18:09
Glay200924-Jan-13 18:09 
GeneralBig Thanks Pin
thewondersnarf11-Mar-11 0:02
thewondersnarf11-Mar-11 0:02 
GeneralMultiSite for XP64 Pin
metastar21-Jan-11 20:53
metastar21-Jan-11 20:53 
QuestionHow do u acutally start the multiple sites at the same time? Pin
RichTrawinski271-Mar-10 16:56
RichTrawinski271-Mar-10 16:56 
AnswerRe: How do u acutally start the multiple sites at the same time? Pin
Gevorg2-Mar-10 2:44
Gevorg2-Mar-10 2:44 
GeneralWorks well, except for long URLs Pin
naasking21-Jul-09 6:55
naasking21-Jul-09 6:55 
This DLL works well enough, unless you need URLs above about 1KB. Then you'll run into odd 404 errors.
QuestionMaybe I'm missing something Pin
Mike william27-Jan-07 16:31
Mike william27-Jan-07 16:31 
GeneralWin 2k Pin
maxwell_hung13-Dec-05 0:35
maxwell_hung13-Dec-05 0:35 
GeneralRe: Win 2k Pin
Gevorg14-Dec-05 17:36
Gevorg14-Dec-05 17:36 
Questiondoesn't like classic asp include files? Pin
tfs_mag17-Oct-05 16:26
tfs_mag17-Oct-05 16:26 
AnswerRe: doesn't like classic asp include files? Pin
Anonymous19-Oct-05 5:18
Anonymous19-Oct-05 5:18 
GeneralDebugging Pin
ekhanh10125-Aug-05 7:31
ekhanh10125-Aug-05 7:31 
GeneralRe: Debugging Pin
Gevorg25-Aug-05 15:21
Gevorg25-Aug-05 15:21 
GeneralRe: Debugging Pin
ekhanh10125-Aug-05 15:30
ekhanh10125-Aug-05 15:30 
GeneralRe: Debugging Pin
ekhanh10125-Aug-05 15:52
ekhanh10125-Aug-05 15:52 
GeneralGreat! Pin
Coderproj15-Jun-05 6:43
Coderproj15-Jun-05 6:43 
GeneralWorking perfect after a few restarts... Pin
28-Apr-05 5:52
suss28-Apr-05 5:52 
QuestionWhich DLL? Pin
Arman27-Apr-05 7:45
Arman27-Apr-05 7:45 
AnswerRe: Which DLL? Pin
Gevorg8-Apr-05 15:32
Gevorg8-Apr-05 15:32 
QuestionIt won't work. What's wrong? Pin
Arman27-Apr-05 7:41
Arman27-Apr-05 7:41 
AnswerRe: It won't work. What's wrong? Pin
Gevorg8-Apr-05 15:59
Gevorg8-Apr-05 15:59 
AnswerRe: It won't work. What's wrong? Pin
dr_fission14-Jul-05 4:37
dr_fission14-Jul-05 4:37 
Generalalmost perfect Pin
jfincke9-Mar-05 5:07
jfincke9-Mar-05 5:07 
GeneralRe: almost perfect Pin
Gevorg9-Mar-05 8:41
Gevorg9-Mar-05 8:41 
QuestionHow is this different than using Host headers in IIS? Pin
Anonymous7-Mar-05 12:45
Anonymous7-Mar-05 12:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.