Hi,
I tried to emulate my site running on a domain in my local machine by using Host Remapping in Fiddler. I am using Visual Studio 2013 and hence the site runs on IIS Express (via CTRL+F5). For example, if IIS Express assigns http://localhost:2491/ to my site, I put:
localhost:2491 test.com
At the Host Remapping setting. However, browser returns: Bad Request - Invalid Hostname HTTP Error 400. The request hostname is invalid.
I can access the site normally via localhost:2491 as expected. So yeah does anyone know the workaround to this?
Thanks in advance!
Ryan.
4 Answers, 1 is accepted
EDIT:
Apparently I can configure it to be accessible via test.com:2491 (still cannot omit port number though) by editing csproj project URL and the IIS Express virtual directory setting. However I would like to have my site accessible from multiple domains (not just one!) in this development machine. For instance, in Fiddler I'd set the Host Remapping setting to:
localhost:2491 test1.com
localhost:2491 test2.com
localhost:2491 test3.com
So I will have multiple domains pointing to the IIS Express instance (preferrably without the port number). Is that even possible?
Thank you in advance.
Ryan.
The issue you're having is that the Host Remapping tool doesn't change the HOST header sent to the server. The Fiddler Book has a long section on how you can retarget traffic by Rewrite, Reroute, or Redirect. The HOSTS tool uses the Reroute method. You want to instead use the Rewrite method, which updates the host header.
This is simply done with the script engine.
Rules > Customize Rules.
Scroll to OnBeforeRequest.
Inside it, add
if (oSession.HostnameIs("test1.com") || oSession.HostnameIs("test2.com") ||
oSession.HostnameIs("test3.com"))
{
oSession.host = "localhost:2491";
}
This will cause the request's Host field to be updated and IIS Express will not know that your request was rewritten.
Regards,
Eric Lawrence
Telerik
See What's Next in App Development. Register for TelerikNEXT.
Thank you Eric! That was much fast and much simpler than I thought. You're awesome :)
UPDATE
After playing with the thing for hours, I realized that Eric's solution is not working as intended because when Request.Url.DnsSafeHost (C#) is accessed, it gives me localhost instead of the used domain name, which is not acceptable for my application development. I found the solution with Eric's hint though:
Full step by step for using custom domain for local ASP.NET development machine with IIS Express:
1. Install Telerik Fiddler, run and edit Tools -> HOSTS and assign "localhost:[port number] domain.name"
2. Open [User Folder]\Documents\IISExpress\config\applicationhost.config and find the application <site> setting entry.
3. Add <binding protocol="http" bindingInformation="*:[port number]:domain.name" /> to the <bindings>
4. Run Visual Studio as Administrator, build and run the application.
Thanks again Eric :D