使用Azure Web App遠端偵錯搭配Visual Studio

Edward Kuo
Oct 18 · 3 min read
Image for post
Image for post

一直知道在Azure Web App可以與Visual Studio 整合,進行遠端偵錯,不過,通常的情境來說,都是可以在本地端就可以找到問題。很少需要透過這方式去找Bug,但是,今天遇到一個Case要本地端進行偵錯就相對困難,主要原因是在於環境上的限制。為什麼呢?在Azure Bot要整合Line Channel,但是一直不知道為什摩會發生Bot接收到Line Message後,就發生錯誤,而這環境是直接在Azure Bot與Line Channel直接建立,並非透過程式去整合。所以,要最快方式找到答案,就是直接開啟Remote Debug。

要進行Azure Web App Remote Debug,首先必須要將你佈署在Azure 環境上的App設定為Debug Mode,這樣才可以開啟偵錯模式(如果本身就是開發模式就不需要),總之必須要讓你的系統處於能除厝模式

Image for post
Image for post

系統設定好之後,接下來就只需要到Azure Web App取開啟偵錯模式,在一般屬性地方,將遠端偵錯功能打開,並指定要使用的Visual Studio的版本

Image for post
Image for post

接下來就回到Visual Studio,開啟Cloud Explorer的視窗,登入你的Azure 帳戶。如果找不到Cloud Explorer的視窗,可以到Visual Studio的View裡面可以找到

Image for post
Image for post

登入帳號之後,接下來就是找到你需要剛剛設定要遠端偵錯的Web Site,然後選取Attach Debugger,就會啟動服務,不過,有一點要強烈建議,如果能不要在正式環境處理這件事,就不要。不然會因為啟動偵錯模式並下中斷點後,會造成雲端服務被中斷。

Image for post
Image for post

一旦啟動Attach Debugger,這時候Visual Studio偵錯模式就會跟雲端整合,因此,服務在雲端有任何動作,在Visual Studio都可以抓得到。不過,偵錯效能一定會比地端差,畢竟還是需要透過網路來回傳遞資訊

EK.Technology Learn

Edward Kuo

Written by

Enterprise IT Manager / Microsoft Regional Director / Microsoft MVP / DevOps Expert / Speaker, About me: https://profile.edwardkuo.dev/about/

EK.Technology Learn

Design,Thinking,Coding & have fun every thing

Edward Kuo

Written by

Enterprise IT Manager / Microsoft Regional Director / Microsoft MVP / DevOps Expert / Speaker, About me: https://profile.edwardkuo.dev/about/

EK.Technology Learn

Design,Thinking,Coding & have fun every thing

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store