user749687
user749687

Reputation:

c# asp.net mvc HttpRequest.URL

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?

Upvotes: 0

Views: 633

Answers (3)

Coofucoo
Coofucoo

Reputation: 119

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.

Upvotes: 0

Prashanth Thurairatnam
Prashanth Thurairatnam

Reputation: 4361

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;

Upvotes: 0

user749687
user749687

Reputation:

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.

Upvotes: 0

Related Questions