问题
I have an ASP.net C# 4.0 website project. I am calling an ASHX handler using a jQuery AJAX postback. Normally when I debug C#, I use this method Debug > Attach to Process > select w3wp.exe and start debugging.
When I do this with my ASHX handler Visual Studio says "The breakpoint will not be hit. No symbols have been loaded for this document." Sure enough, when I run the AJAX call to the handler, the breakpoint is not hit.
What confuses me is that I can debug C# files otherwise, i.e. the code-behind of an ASPX file.
回答1:
It turns out that Visual Studio will not actually load symbols for debugging until it actually tries to run the ASHX handler. My problem turned out to be elsewhere - a bug in the jQuery code that called the handler.
I didn't see this bug at first so assumed the handler was being hit. Once the handler is called, VS will then allow you to debug it. I didn't realise that ASHX handlers behaved this way, I thought they would work just like a regular C# file.
回答2:
This is generally because what you are looking at (the code) is not what you are running.
Try to throw in Debugger.Launch();
and see if that attaches the debugger correctly. If it does then your problem is simply that you are view a different copy/version of the code that's unrelated to the debugging
回答3:
Is there only one w3wp.exe try right clicking your asp.net project select "Debug" and "Start a new instance" from context menu.
来源:https://stackoverflow.com/questions/15202903/c-cant-debug-ashx-handler