---------- 20191117 摘要: visual studio 2015 可透過以下設定方式, 以IIS express 支援 Localhost 以外的瀏覽網址: 1. 修改 .vs\config\applicationhost.config檔案中, site 節點之 binding 中的 localhost. 例如原來為: 如果要用其他網域名稱, 例如www.011.idv.tw, 可改為 localhost 直接換成公網域名即可,vs不需要使用管理員許可權開啟 如果用自定義域名, 例如anyname, 可改為 localhost 直接換成自定義域名, 並以系統管理員修改 \Windows\System32\drivers\etc\hosts檔案, 增加相同一筆自訂義域名. 如果要使用區域網ip, 例如 192.168.0.57 或 127.0.0.1 可改為 ----> 20191117, 測試OK ----> 20191117, 測試OK 2. 除了廣域網址不需要系統管理員以外, 其他方式都必須以系統管理員權限, 重新開啟Visual Studio 2015. 修改 專案 Property 中的 Web, 其中 Servers段落應為 IIS Exprss, 且 Project Url 應與第1點的設定內容相同, 例如: http://127.0.0.1:55387/ 3. 檢查 IIS express 應用程式執行清單,會有以上設定的ip或網域名稱. ---------- VS2015 使用IIS Express 支援非localhost訪問 https://www.itread01.com/content/1549814941.html 使用VS2015 開發C# web工程,使用IIS Express 作為伺服器。自己開發,自己測試沒問題,讓其他人員訪問測試的出現 Bad Request - Invalid Hostname HTTP Error 400. The request hostname is invalid. 我的機器是區域網和公網都可以訪問的,有一個區域網ip 192.168.8.110,在路由器上做了埠對映,將5678埠對映到了本機的5678埠。 無論用192段ip,還是公網ip,還是127.0.0.1都出現上面那個錯誤。 百度一下: http://www.cnblogs.com/liluping860122/p/4685564.html 找到一位大俠的解決方法,寫的很棒。 主要是修改 : 工程路徑\.vs\config 資料夾下面的applicationhost.config 這個檔案,找到site 那個節點,修改bindings 屬性,這其實給在iis中編輯繫結是一樣的意思。 具體修改的內容有幾點注意的: 1 如果用實際公網域名 localhost 直接換成公網域名即可,vs不需要使用管理員許可權開啟 2 如果用自定義域名 localhost 替換為自定義域名,如果是管理員許可權開啟不需要編輯系統的hosts檔案,如果是普通許可權開啟,需要編輯hosts檔案 我是win7系統,hosts檔案在 C:\Windows\System32\drivers\etc 下面,是隱藏的,所以要從系統選單-工具-資料夾選項-的顯示中選擇顯示隱藏的資料夾。 我在修改的時候,安裝的防毒軟體小紅傘阻止修改host,選擇允許就可以儲存了,不然會提示有其他檔案正在開啟,不讓儲存。 3 如果使用區域網ip 將localhost 換成具體的ip即可, 例如 改成 注意一定要用管理員許可權開啟vs。不然還是不能的。 修改完畢config後,重啟下VS,重啟的時候選擇是否以管理員的身份執行,開啟VS後,執行專案,可以看到右下角的IIS express 托盤中-檢視全部執行程式,會有剛才設定的ip。 區域網ip能使用後,我的外網ip自動也就可以使用了。 ---------- 20191117 Monitor traffic to localhost from IE or .NET https://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/MonitorLocalTraffic?_ga=2.148816311.1284916363.1573995920-541964882.1510758463 To monitor traffic sent to http://localhost or http://127.0.0.1 from IE8 or below or the .NET Framework: Use your machine name as the hostname instead of Localhost or 127.0.0.1 以電腦名稱監視, 不要使用 localhost 或 127.0.0.1 For example, instead of http://localhost:8081/mytestpage.aspx Go to: http://machinename:8081/mytestpage.aspx Use one of these addresses: -To use the IPv4 adapter (recommended for the Visual Studio test webserver, codename: Cassini): http://ipv4.fiddler -To use the IPv6 adapter: http://ipv6.fiddler -To use localhost in the Host header: http://localhost.fiddler Click Rules > Customize Rules... and add this code to the Rules file: static function OnBeforeRequest(oSession:Fiddler.Session){ if (oSession.HostnameIs("MYAPP")) { oSession.host = "127.0.0.1:8081"; } } Now, http://myapp will act as an alias for 127.0.0.1:8081 http://localhost:55387/WebAPI/Post1.html ---------- 20181229 visual studio 2015 執行時不能使用 localhost 請求, 須改用machinename: ref: https://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/MonitorLocalTraffic To monitor traffic sent to http://localhost or http://127.0.0.1 from IE8 or below or the .NET Framework: 1. Use your machine name as the hostname instead of Localhost or 127.0.0.1 For example, instead of http://localhost:8081/mytestpage.aspx Go to: http://machinename:8081/mytestpage.aspx 2. Use one of these addresses: -To use the IPv4 adapter (recommended for the Visual Studio test webserver, codename: Cassini): http://ipv4.fiddler -To use the IPv6 adapter: http://ipv6.fiddler -To use localhost in the Host header: http://localhost.fiddler 3. Click Rules > Customize Rules... and add this code to the Rules file: static function OnBeforeRequest(oSession:Fiddler.Session){ if (oSession.HostnameIs("MYAPP")) { oSession.host = "127.0.0.1:8081"; } } Now, http://myapp will act as an alias for 127.0.0.1:8081 ---------- 20181229 消除不斷出現的vshub, 輸入以下欄位資料: Fiddler.Filters.Request Headers.Hide if URL Contains."vshub" ---------- 20181229 Configure .NET Applications ref: http://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/ConfigureDotNETApp To allow the .NET Framework to automatically connect to Fiddler, start Fiddler before starting the .NET application. To temporarily connect a .NET application to Fiddler, use the GlobalProxySelection class to set a proxy: GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888); Or, specify a proxy inside the yourappname.exe.config file. If the .NET application is running in your current user account, add the following content inside the configuration section: See MSDN for more on this topic. If the .NET application is running in a different user account (for example, a Windows service), edit the machine.config file: Or, manually specify the proxy on an individual WebRequest object: objRequest = (HttpWebRequest)WebRequest.Create(url); objRequest.Proxy= new WebProxy("127.0.0.1", 8888); Note: Important: Regardless of other settings, .NET will always bypass the Fiddler proxy for URLs containing localhost. So, rather than using localhost, change your code to refer to the machine name. For instance: This URL will not appear in Fiddler: http://localhost/X509SignCodeService/X509SigningService.asmx This URL will appear in Fiddler: http://mymachine/X509SignCodeService/X509SigningService.asmx ---------- 20181228 Capturing Traffic from .NET Services with Fiddler ref: https://www.telerik.com/blogs/details/capturing-traffic-from-.net-services-with-fiddler 啟動 Fiddler 後, Fiddler 會自動將目前使用者的 proxy 指向 Fiddler (即: 127.0.0.1:8888), 代表所有的資料流都會流向 Fiddler. When Fiddler launches and attaches, it adjusts the current user’s proxy settings to point at Fiddler, running on 127.0.0.1:8888 by default. That means that traffic from most applications automatically flows through Fiddler without any additional configuration steps. 但若是要捕捉到不同使用者帳號的資料流 - 例如 要捕捉到 Web Service ... todo...先測試 適用IIS_Express, 結果: Visual Studio 2015 變成無法啟動. However, sometimes you might want to capture traffic running in a different user account – for instance, you may want to capture web service calls from an ASP.NET page to a web service running on a different machine, or you might want to debug the traffic from a Test Studio Load Test agent, which runs under a service account. Fortunately, if you’re an administrator, it’s pretty easy to get .NET Services to point at Fiddler. Simply open the machine.config file and add a new defaultProxy setting that points at Fiddler: 1. Start Fiddler. 2. Launch Notepad elevated (as an Administrator). 3. Open machine.config in the folder C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config. Note that if you are debugging a 64bit service (like ASP.NET) you will want to look in the Framework64 folder instead of the Framework folder. Similarly, if you are using a .NET version prior to 4.0, you will need to adjust the version part of the path. 4. Add the following XML block as a peer to the existing system.net element, replacing any existing defaultProxy element if present: It should look like this: 5. Save the file. 6. Restart the services. Most services are restarted using the Services MMC applet, but for Test Studio, you can use the Start/Stop buttons in the Test Studio UI: After this configuration change is made, traffic from services should begin to flow through Fiddler: When you’re done debugging, be sure to revert your changes to machine.config and restart the services. If you forget to undo your changes, you’re likely to find that all of your services can no longer reach the network the moment that Fiddler is shutdown.