[英]Connecting to Visual Studio debugging IIS Express server over the lan
我有一個在VS2012中開發的測試ASP.NET MVC3應用程序。 當我開始調試時,通過對http://localhost:<portnumber>
的請求從主機訪問應用程序。 但是,如果我嘗試通過http://<ip>:<portnumber>
從Intranet中的遠程計算機訪問同一個應用程序,我收到HTTP error 400: Bad request. Invalid Host Name.
HTTP error 400: Bad request. Invalid Host Name.
就它在IIS Express上運行而言,任何服務器配置都是不可訪問的。
有什么方法可以解決這個問題嗎?
更新
我制作了一個更好地描述過程的視頻, https://youtu.be/5ZqDuvTqQVs
如果您使用的是Visual Studio 2013或更高版本,請確保以管理員身份運行它以使其工作。
%USERPROFILE%\\My Documents\\IISExpress\\config\\applicationhost.config
(在VS2015中可能是$(solutionDir)\\.vs\\config\\applicationhost.config
.vs $(solutionDir)\\.vs\\config\\applicationhost.config
)文件。
在里面你應該看到這樣的東西:
<site name="WebSite1" id="1" serverAutoStart="true"> <application path="/"> <virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\\WebSite1" /> </application> <bindings> <binding protocol="http" bindingInformation="*:8080:localhost" /> </bindings> </site>
將bindingInformation=":8080:localhost"
更改為bindingInformation="*:8080:*"
(端口號,在我的情況下為8080,將有所不同。)
注意:如果不起作用,請嘗試使用bindingInformation="*:8080:
可以刪除星號。
然后確保您的防火牆允許該端口上的傳入連接。 您可能需要重新啟動系統或至少Visual Studio以使IISExpress重新加載配置文件。
如果這不起作用,請看看這個答案: https : //stackoverflow.com/a/5186680/985284
在您的解決方案目錄中,在.vs\\config\\applicationHost.config
文件中更改該行
<binding protocol="http" bindingInformation="*:44302:localhost" />
至
<binding protocol="http" bindingInformation=":44302:" />
(44302是你的港口)
從管理員命令提示符:
一世。 啟用非管理員綁定到端口
netsh http add urlacl url=http://*:44302/ user=Everyone
II。 允許通過防火牆
netsh advfirewall firewall add rule name="IISExpress visualstudio app" protocol=tcp localport=44302 dir=in action=allow
除了修改iisexpress配置文件外,有時您還需要運行如下命令。
netsh http add urlacl url = http:// *:49419 / user = Everyone
由於我無法在@Garret Fogerlie的帖子中添加評論並回應評論者的問題(@ Y.Ecarri和@SamuelEdwinWard),我遵循Garret建議的,使用Visual Studio 2013,在管理模式下運行並更改application.config
文件。
在啟動調試並看到我收到相同的錯誤消息之后,我又回到了application.config
並看到我的網站的新條目已經創建,就像Y.Ecarri的問題一樣。
所以我停止了調試, 在Visual Studio中保持我的解決方案打開 ,並再次為新條目編輯了application.config
文件。 我也完全刪除了*
sings和localhost
,所以我對新條目有以下內容:
<binding protocol="https" bindingInformation=":44300:" />
如何避免以管理員身份運行Visual Studio
使用Garret和@ shangkeyun的答案,您可以實現連接到正在運行的網站,而無需以管理員用戶身份運行Visual Studio:
%USERPROFILE%\\My Documents\\IISExpress\\config\\applicationhost.config
name=MySiteName
搜索您的站點 <bindings>
部分中的現有<binding>
項。 你現在應該有兩行binding
。 它現在應該是這樣的,假設端口是12345
:
<binding protocol="http" bindingInformation="*:12345:localhost" /> <binding protocol="http" bindingInformation="*:12345:" />
啟用非管理員綁定到端口
netsh http add urlacl url=http://*:12345/ user=Everyone
編輯2019:gregmac添加了一個步驟,將VS實例列入白名單。 我從來不需要這個,但無論如何列出它:
netsh advfirewall firewall add rule name="IISExpress visualstudio app" protocol=tcp localport=12345 dir=in action=allow
感謝byteit:
轉到Documents / IISExpress / config中的applicationhost.config
找到您正在處理的特定網站的條目:
加:
<binding protocol="http" bindingInformation="*:<your site port>:*" />
在現有的面前
<binding protocol="http" bindingInformation="*:<your site port>:localhost" />
要在沒有VS2013的情況下實現解決方案,請在重新啟動時為您創建新的網站xml條目。 您需要以管理員身份運行。
你們中的一些人可能會花費大量時間使用%USERPROFILE%目錄進行修改和測試。 如果您在VS調試上運行,請使用$(solutionDir).vs \\ config \\ applicationhost.config
這對我有用:
C:\\VSProjects
) Directory Browsing
”。 在右側有一個Enable
按鈕。 點擊它。 現在我可以通過mypcname\\VSProjects\\myProj\\outputBinViewer
訪問網絡上的文件夾和項目bin。
如果在Visual Studio Code中調試一個非常類似的問題,我通過添加以下內容解決了它:
"env": {
// ...
"ASPNETCORE_URLS": "http://*:5000" // change to the port you are using
// ...
},
.. to launch.json
顯然,默認情況下它會將http協議綁定到“localhost:5000”,因此它可以與localhost配合使用,但不能與ip地址配合使用 - 既不是遠程也不是本地。
如果您嘗試通過來自其他計算機的請求來查找斷點,請不要忘記檢查防火牆設置(和/或防病毒)
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.