Reputation: 1385
I've got a single page, .aspx
, file that contains some JavaScript code and some C# code. There is no code-behind file. The C# code is:
<script language="c#" runat="server">
protected void Page_Load(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
string auth = Request.Headers["Authorization"];
label1.InnerText = auth;
return;
}
</script>
I have created a web page referencing a local website under IIS. I am running this in Visual Studio 2017 with administrator privileges. Nevertheless, I cannot set a breakpoint within the C# code. I just get the following notice
A breakpoint could not be inserted at this location."
Is there some restriction in setting a breakpoint is code that does not exist in a separate code-behind file?
Upvotes: 0
Views: 4135
Reputation: 1
Even though Visual Studio may not allow you to insert a breakpoint in an .aspx file, you can edit the .aspx and insert a call to System.Diagnostics.Debugger.Break() and that will trigger a breakpoint when the page is rendered.
Upvotes: 0
Reputation: 4992
You should be able to do that. In my experience, the ability to set break point is not stable. When VS disallows that, here is something you can try to enable it:
Upvotes: 1
Reputation: 8597
That's because the page gets rendered when its loaded so that's not compiled code and thus you can't set a breakpoint since the compiler isn't aware of it.
Here's a quote from MSDN Page:
Embedded code blocks are supported in ASP.NET Web Forms pages primarily to preserve backward compatibility with older ASP technology. In general, using embedded code blocks for complex programming logic is not a best practice, because when the code is mixed on the page with markup, it can be difficult to debug and maintain. In addition, because the code is executed only during the page's render phase, you have substantially less flexibility than with code-behind or script-block code in scoping your code to the appropriate stage of page processing.
Upvotes: 0