0

I have an ASP.net web application that has different functionality and data depending on the URL that it is logged in as.

Everything works fine in a deployed environment as I can bind several hosts in IIS and the web application can then interrogate the request.URL to work out which code and data to use.

eg. http://foo.bar.com will run different code than http://test.bar.com

The problem arises in debugging in VS2010 on my development machine. I can hard code a default site url in the configuration but require several to be run at the same time. e.g site1.localhost, site2.localhost, site3.localhost ....

I have tried editing my hosts file in system32/drivers/etc e.g

127.0.0.1  localhost site1.localhost site2.localhost

but if I hit site1.localhost in my code the request.Url is always localhost

Is there anyway I can get around this?

5
  • Have you tried multiple host-file lines... Commented May 22, 2012 at 2:05
  • Are you hosted in IIS? Do you have the site bound to site1.localhost and site2.localhost? Commented May 22, 2012 at 2:09
  • no this is running on my localmachine running debug in Visual studio, I guess I could also try and host IIS for the same directory and build the site and test like this setup msdn.microsoft.com/en-us/library/a1zz9df4.aspx but i want to run in debug Commented May 22, 2012 at 2:13
  • 1
    You can debug a site running on IIS by attaching the process - sorry Debug -> Attach Process --> The w3wp (www worker process) is the one you want - usually there's some description for which site each process is servicing Commented May 22, 2012 at 2:15
  • Was hoping for a simpler solution with hosts, rebuilding, restarting IIS and then attaching debug to the IIS process is very unfriendly Commented May 22, 2012 at 2:18

3 Answers 3

0

If you have mapped your host name in system32/drivers/etc/hosts, try this code. This should return the correct path

     string host = Request.Headers["Host"];
     string pathAndQuery = Request.Url.PathAndQuery;

     string fullPath = host + pathAndQuery;
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, now why didn't I think of that. Thanks
0

Based on mfras3r comments. I can get it to work via

Setting up a website in IIS, point that web site to the directory of my MVC application. Add the bindings for all the urls to the website in IIS. Add the urls as entries in /etc/hosts pointing to localhost.

Build the application. ( Don't run it as it will screw up due to IIS) Debug -> Attach to IIS process.

Comments

0

I think the debug server in vs2010 is not a full featured IIS. It do not support multiple site. So in your situation, it is better to use "attach" or remote debug. It is depends on whether you can install IIS on your development machine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.