This is a migrated thread and some comments may be shown as answers.

Need Help on Fiddler Host Remapping, HTTP Error 400 (Bad Request)

4 Answers 1787 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 09 Apr 2015, 05:14 AM

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

Sort by
0
Ryan
Top achievements
Rank 1
answered on 09 Apr 2015, 05:52 AM

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.

0
Accepted
Eric Lawrence
Telerik team
answered on 10 Apr 2015, 12:14 AM
Hi, 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.

 
0
Ryan
Top achievements
Rank 1
answered on 10 Apr 2015, 02:33 PM

Thank you Eric! That was much fast and much simpler than I thought. You're awesome :)

0
Ryan
Top achievements
Rank 1
answered on 10 Apr 2015, 04:28 PM

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

Tags
Fiddler Classic
Asked by
Ryan
Top achievements
Rank 1
Answers by
Ryan
Top achievements
Rank 1
Eric Lawrence
Telerik team
Share this question
or