Click here to Skip to main content
Click here to Skip to main content

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

By , 8 Apr 2005
 

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

About the Author

Gevorg
Web Developer
United States United States
Member
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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Question4.0 versionmemberGlay200924 Jan '13 - 18:09 
Hi,
 
D you have a 4.0 veriosn for this dll? Also, do you have an example and guide on how to implement this. I am new in .Net multisite and I dont's knoe where to start. Many thanks.
 
Regards,
GeneralBig Thanksmemberthewondersnarf11 Mar '11 - 0:02 
I love this, works a charm. Thanks for sharing...
GeneralMultiSite for XP64membermetastar21 Jan '11 - 20:53 
Recompiled to run on XPx64 platform...
 
http://deiulio.com/MultiSiteX64/MultiSiteX64.dll[^]
QuestionHow do u acutally start the multiple sites at the same time?memberRichTrawinski271 Mar '10 - 16:56 
I understand and have implemented everything here, however it still seems that the multiple definied sites need to be started in order for this to work. What am I missing?
AnswerRe: How do u acutally start the multiple sites at the same time?memberGevorg2 Mar '10 - 2:44 
To tell you the truth i am not using this approach for long time already.
Starting .NET 2.0 there is built in web server into .NET and there is pretty much no difference between it and IIS (from development view)
 

Here is the command to run your project from root. C:\inetpub\wwwroot\XoopsNet is the folder where web application is (in my case).
"C:\Windows\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE" /port:103 /path:C:\inetpub\wwwroot\XoopsNet
 
Then if you hit http://localhost:103 and it will work as from the root.
 
You will be able to debug it.
1. Start a server
2. In Options for the project, Start Options modify it to 'Use custom server' and Base url put http://localhost:103
(it's for visual studio express), Visual studio will have slightly different name, but has that option.
 
Luckily Visual Studio (expres or not express) remember that setting, so you do not need to do it everytime, Just start the server first, It runs in the background. So you need to start it again only when you shutdown your machine.
 
PS: Obviously if you change port 103 to 80, you do not need to specify port number, just make sure IIS is not running since it takes port 80 by default.
PPS: Majority of projects will not even notice that it's not IIS. You need to pay attention when you using security. Built-in servers runs under your account and IIS has his own account, hence the access to files or shared folders... will be different.
My site - Body Jewelry
Not my site - Piercing info

GeneralWorks well, except for long URLsmembernaasking21 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 somethingmemberMike william27 Jan '07 - 16:31 
Running XP Pro SP2 and using Multisite and Config from your Demo file.
Config looks like
[websites]
1.site.com=/Test1
2.site.com=/Test2
 
Hosts looks like
 
127.0.0.1 localhost
127.0.0.1 www.1.site.com
127.0.0.1 www.2.site.com
 
IIS Local Path is D:\Websites
\Test1 one and \Test2 are under D:\Websites
 
Restarted IIS
 
www.1.site.com gives error 403
 
When changing Local Path to D:\Websites\Test1 it works when I type www.1.site.com but www.2.site.com goes to the same website. What am I missing? Do I need a virtual directory? do I need a completely seperate domain name? I'm trying to get this working but am not having little luck.
 
Your help is appreciated.
 
Thank you very much.
 
Michael
GeneralWin 2kmembermaxwell_hung13 Dec '05 - 0:35 
I installed this on my XP pro machine and it seems to work great but on win 2k it doesn't
 
config file is
[websites]
test.local=/test
 
when I browse to test.local/default.aspx
 
I get a .net error saying it can't find the file at
/test/default.aspx
 
thanks
GeneralRe: Win 2kmemberGevorg14 Dec '05 - 17:36 
Should work on Win2K.
 
If you are getting .NET error that means the ISAPI filter worked and .NET should have picked up correct file /test/default.aspx which looks like does not exist.
 
Please test that http://localhost/test/default.aspx works.
 

 
George.
 
My site - Body Jewelry
Not my site - Piercing info
Questiondoesn't like classic asp include files?membertfs_mag17 Oct '05 - 16:26 
I have some .net projects i've setup here, and some classic asp. On the classic asp projects when i do an include virtual="/thefile.asp"- it reads it as /website/thefile.asp? give me an error that says it can't find the page Frown | :(
 
any work around on that, that won't require me go through every page with an include?
AnswerRe: doesn't like classic asp include files?sussAnonymous19 Oct '05 - 5:18 
nevermind... this ISAPI filter seemed to buggy and wouldn't work right with classic ASP.
 
I went and downloaded/installed this http://www.firstserved.net/services/iisadmin.php
 
works perfect, and all you have to do is edit your host file to go to dev.yoursite.com and use this tool to set up your sites.
GeneralDebuggingmemberekhanh10125 Aug '05 - 7:31 
Hi,
I got this to work in IIS and the URL points properly and load via VS.
But when I try to debug, I get the following error:
 
Error while trying to run project: Unable to map the debug start page URL to a machine name.
 

Debuggin works fine if I didn't use multisite.dll and go to localhost.
 
but when I implement this solution.
the site comes up, http://mymachine.com/ perfect
 
just can't start debugger.
 
any ideas?
 

thanks
GeneralRe: DebuggingmemberGevorg25 Aug '05 - 15:21 
Try to modify folowing files
1. projectname.csproj.webinfo
2. project.sln
Change the localhost to mymachine.com
 
Works for me. Also ou can try following (it will be exactly how i have it setup).
 
1. Copy sln file to the folder where project is (in Inetpub).
2. Try to drop .com may be that is the problem (I do not use .com)
 
---------------------------------------------------------
 
If it does not work you can always use your project as is with localhost but when you start the debugger launch second IE and open up http://mymachine.com/perfect
 
The debugging will work and i actually find it more convinient. Since that window never closes even when you stop debugging.
 

George
 


 
My site - Body Jewelry
Not my site - Piercing info
GeneralRe: Debuggingmemberekhanh10125 Aug '05 - 15:30 
Hi George,
thanks for trying to help.
Yes, i've modified all those files.
and it's just mymachine (not .com)
 
and so yes, it will open up in VS (if i didn't modify those files at all,
the project wouldn't even load) , but can't start the debugger.
 
The problem, is the debugger won't start at all..
gives that error.
so I can't even start debugger, and go to IE and open http://mymachine/
 
but oustide the VS i can go to http://mymachine
 
all three files are in the folder of the subsite...
 
It's supposed to be a VirtualDirctory under the Default Web Site right?
all files are in the Folder in the Virtual Dir...
 
Anything else you can think of?
 
thanks,
 

 

GeneralRe: Debuggingmemberekhanh10125 Aug '05 - 15:52 
i got it working now.
 
first i made the directory, browsable,etc.. so when i do open project from Web it works.
But when Open Project from web, i had chosen the solution (sln) file instead of the (.proj ) file once I chose the proj file it works.
 
it think part of the problem was the .sln file was not be able to overwrite itself or something, cuz when i did debug this time it ask what to save the .sln file as...
 

oh well, it works...thanks...

GeneralGreat!memberCoderproj15 Jun '05 - 6:43 
You can even create a secured WebDAV folder like: https://sub.domain and it will open domain/sub
 
MS should implement this for subwebs. After all, the main purpose of IIS 5.1 is to test sites before uploading to a production server, so using the same syntax is essential.
GeneralWorking perfect after a few restarts...memberRichard Bladh28 Apr '05 - 5:52 
I finally got this working, both in design-time and run-time...
For the projects to work in design-time I needed to change the *.webinfo and *.sln files to map to the url defined in the hosts-file.
 
At first I couldn't get VS.NET to open my projects, but after a few restarts of both IIS and the computer it is working as a charm.
 
I will have great use of this functionality in my upcoming projects - so many thanks to you!
 
Best regards,
Richard
QuestionWhich DLL?memberArman27 Apr '05 - 7:45 
Both in the "source" and the "demo" version, a MultiSite.dll is included. The first, in de \Debug folder of the "source" version, has a size of 300kB, the second, "demo" version, is 65 kB.
Which one should be used and what is the difference?
 
(I'm not familiar with the .Net environment.)
 
Regards, Arman
AnswerRe: Which DLL?memberGevorg8 Apr '05 - 15:32 
Use demo version. it's a release compiled version. So it work faster than debug version.
 
My site - www.tersaakov.com
QuestionIt won't work. What's wrong?memberArman27 Apr '05 - 7:41 
I tried your ISAPI filter, but I don't get it working. Perhaps I didn't understand your setup instructions completely. My web development environment contains WinXP Pro - IIS 5 - Dreamweaver MX.

This is my situation:
1) On IIS, in the Default Web Site, I have a folder named ABS, this contains a test website.
2) I also have a Virtual Directory called "DEF" in the Default Web Site, pointing to a folder somewhere on a shared drive containing another website.
3) In the "host" file, I added the following lines: 127.0.0.1 www.abc.org and 127.0.0.1 www.def.net.
4) I copied the Multisite.dll and config.ini to a separate folder and added the ISAPI filter to the Default Web Site properties. (Installing it in the Web Sites properties results in a "not loaded" status.)
5) In "your" config file, I added the following lines: www.abc.org=/ABC and www.def.net=/DEF.
6) I restarted IIS.

This is what happens in the browser (IE6):
- address: www.abc.org --> shows the top (wwwroot) default page.
- address: www.def.net --> shows the top (wwwroot) default page.
So, apparently the Multisite DLL doesn't work here.

Please, help me to understand what's wrong.
Regards,
Arman
AnswerRe: It won't work. What's wrong?memberGevorg8 Apr '05 - 15:59 
I see were problem is.
Change ini file as following.
abc.org = /ABC
def.net = /DEF
 
The www prefix is stripped out. So it works like in real world with www and without.
But keep in mind that in host file you need to have 2 lines one with www and one without.
 
Let me know if it's working or not.
I actually forget to mention it in the article. I will modify it.
 
Thanks
George.
 
My site - www.tersaakov.com
AnswerRe: It won't work. What's wrong?memberdr_fission14 Jul '05 - 4:37 
I'm still a little new to this filter, but I believe the problem is the following:
 
Arman2 wrote:
3) In the "host" file, I added the following lines: 127.0.0.1 www.abc.org and 127.0.0.1 www.def.net.
 
Depending on how the server is attached to the network, 127.0.0.1 will be altered.
 
I am running a bank of redundant hardware behind a gateway/router firewall using WinXP Pro and the standard IIS 5.1. It requires me to alter the IP address to the LAN address on each host file. And I keep the DLL and INI over on my system32 directory.
 
Therefore, I alter 127.0.0.1 to the standard LAN format 192.168.[LAN #].[machine #] where I assigned the [LAN #] and the [machine #] in the gateway/router. Its a Linksys wireless gateway/router.
 
If the server is connected directly to the WAN via a modem only, then I'm guessing the IP address will be the cable IP address.
 
Once I did this the whole multisite.dll ISAPI filter took off like a big-assed bird. I run over 20 different web sites from my cable connection and the most diverse menagerie of web pages you could ever see, ranging from the mundane [HTML] to ASP, to MS database. I even run concurrent FTP and SMTP servers out of IIS 5.1. No need yet to run the NN server, but the day could come.
 
My only suggestion is to take the framework of multisite.dll and create another filter that will take the place of the IP address block function that was also removed from IIS 5.1. The new filter could be placed at either a higher or lower ISAPI priority (depending on the situation) than multisite.dll. The INI file could contain a list of specific IP addresses or IP address blocks and an associated file, return code, or null response that is sent (or not sent) to those addresses.
 
The same type of filter could be used to deactivate certain methods. Additionally, with a little more complicated coding structure repetitive hits on a server from a single IP address in a short period of time could be eliminated with a counter/timer filter. These suggested approaches, of course, would be used to discourage less desireable elements on the internet.
 
Is Gevorg up to the challenge? If he doesn't have the time he could delegate the challenge. I could get the first filter up in a relatively short period and have it posted here for all.
Generalalmost perfectsussjfincke9 Mar '05 - 5:07 
This is (almost) a perfect solution for me. I'm trying to get a legacy asp application under control. It runs in the root directory in production and on my development machine (XP Pro) it almost works when I use the MultiSite DLL. There's a url in a Server.Execute() statement that isn't working. I'm new to asp and JScript but I assume the problem is that this is executed in process on the server and never touches the isapi filter. Any suggestions?
GeneralRe: almost perfectmemberGevorg9 Mar '05 - 8:41 
You are correct. The problem with Server.Execute (or Server.Transfer) is that it works on a server so it does not go through ISAPI filter.
 
The solution is to use it with '~' symbol. Like Server.Execute("~/mypage.aspx") then it will work. ASP.NET will automatically translate it to "/project/mypage.aspx"
 
If you are using ASP then unfortunatelly there is no easy solution like with ASP.NET. Could not think of any except to hardcode the project folder name there. Or replace Server.Execute with Reponse.Redirect.
 
My site - www.tersaakov.com
QuestionHow is this different than using Host headers in IIS?sussAnonymous7 Mar '05 - 12:45 
How is this any different/better than using host headers in IIS 5.0+?
 
http://www.windowsitpro.com/Windows/Article/ArticleID/21205/21205.html
 

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 8 Apr 2005
Article Copyright 2005 by Gevorg
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid