0

Update If I use Fiddler, I see I get a 200 OK Response but the following message:

{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}

I have no idea where that's coming from.

Original Post
When I place a breakpoint in the web method it is never hit. The success handler runs for the ajax call. If I change the name of the url to incorrect value, I do get an error in F12 tools that it is not found.

I've tried EnablePageMethods='true' as well on the ScriptManager.

JavaScript lives in Scripts folder

$.ajax({
    type: 'POST',
    url: 'Tasks.aspx/UpdateStatus',
    contentType: "application/json; charset=utf-8",
    data: '{ id: 8, status: 1 }',
    success: function (data) {
        alert('it worked!');
    },
    failure: function (response) {
        alert(response.d);
    }
});

Tasks.aspx.cs code behind

[WebMethod(EnableSession = true)]
public static string UpdateStatus(int id, int status)
{
    TaskManager taskManager = new TaskManager();
    taskManager.UpdateStatus((TaskStatuses)status, id);
    return string.Empty;
}
Rod
  • 14,529
  • 31
  • 118
  • 230
  • Did you connect to the correct process? Is the build the same in your IDE as the executing process (this can cause breakpoints not to be hit). In your c# code add `System.Diagnostics.Debugger.Break();`, this will force a prompt asking you if you want to attach your IDE to debug the code. – Igor Apr 03 '18 at 20:54
  • I would suggest you edit the title of this question to "Debugger not stopping on breakpoint" and include the development product/version that you are using. – Scott Marcus Apr 03 '18 at 21:08
  • Possible duplicate of [Why would the debugger not be stopping at a breakpoint in my ASP.NET application?](https://stackoverflow.com/questions/856643/why-would-the-debugger-not-be-stopping-at-a-breakpoint-in-my-asp-net-application) – Igor Apr 03 '18 at 21:10
  • 1
    The failure is occurring before the web method is executed, during the authentication step. For example, there could be a problem parsing your token. ASP.NET will not pass control to the web method in this scenario. – John Wu Apr 03 '18 at 22:22
  • Agree with John Wu. You might need to call a new service-method that checks if the user is authenticated first (return a bool). You could also try adding `data: JSON.stringify({ "id": 8, "status": 1 })`, or just the quotes. – wazz Apr 04 '18 at 00:07

1 Answers1

0

I ended up changing PageMethod in the code-behind to a web service asmx file and that seemed to have worked. Now I have to figure out how to secure it.

Rod
  • 14,529
  • 31
  • 118
  • 230