问题
I was finally able to get a legacy site to run, in my regular/preferred browser - Chrome. I was trying to see how to step through the javascript code there in the F12 tools. When I couldn't see how to access the script code, I did some research, and found that javascript debugging of ASP.NET projects can (supposedly?) only be done in IE.
So in the project, I switched the browser to use from Chrome to IE. Now when I try to open the site from the VS IDE, it breaks with an exception:
Why would Chrome merrily ignore this, or why does IE grouchily make an issue of it?
In Chrome, I see various ScriptResource files:
...but these seems to be everything BUT the custom javascript for the site - Microsoft and Telerik code.
This ASP.NET site targets .NET 3.5; IE 11; Visual Studio 2013.
回答1:
you are requesting an item from the Cookies collection. It is very likely that this cookie exists Chrome, where it does not give the exception. And probably this cookie does not exist in Internet Explorer, where you get the exception.
Always check if the result if Request.Cookies[...] is null before further processing.
回答2:
Check the place where you are initializing the Request.Cookies(PortalHelper.BUTTON_MEMBER) to verify that you're actually running that code before you're expecting the value to be there. Set a breakpoint at that line of code AND at the erroring line of code, then run through IE via IDE to see which code gets run first.
From the IDE, you're likely skipping over a portion of code that through Chrome you either are not or you've initialized at a prior time through some other workflow.
回答3:
Not sure if you're asking for a fix for your actual code issues? Or just asking in the difference in behavior between chrome and IE?
If the latter, it's just that VS is launching an IE js debugging session and breaks on an error (you see the JS being debugged in VS). This was a useful feature back when browser dev tools were still pretty nascent (especially for IE), now not so much. No such VS browser debug session when you run with chrome, hence the silent run through.
IE will also give a silent run through if you just open a fresh browser and hit the URL to your running server (it won't have the VS process hook).
来源:https://stackoverflow.com/questions/41065628/why-do-i-get-an-exception-in-ie-but-not-chrome-when-running-my-asp-net-site