John John - 3 months ago 10
ASP.NET (C#) Question

Run application in debug and hit breakpoint by using URL

When using MVC if I want to run a test on the "People" function in the home controller I can use a breakpoint at the People function and run the application in debug mode and use the URL in a browser:

http:/LH_P/Home/People


this stops at the breakpoint. Simple Q I hope but can't seem to get it for ASP.NET application.

So I want to enter a URL that will hit the breakpoint at the TEST() function in the Default.aspx.cs page.

Tried something like:
http://LH:PortNumbner/Default.aspx/Test

Answer

In .aspx pages it doesn't work like that. You can't just call a function by using the /FunctionName as you do in MVC. You'll need to call the function in the page load method like below.

Run only the first time the page loads:

 protected void Page_Load(object sender, EventArgs e)
 {
    if(!Page.IsPostBack)
    {
      Test();
    }
 } 

Run every time the page loads:

 protected void Page_Load(object sender, EventArgs e)
 {
    Test();       
 } 
Comments