AJAX调用未命中异步处理程序中的断点
我编写了一个在按钮按下事件中调用的快速AJAX脚本,该事件反过来调用asysnc处理程序从远程API中提取数据。我修改了同一个脚本来调用另一个非异步的处理程序,它工作得很好,我不知道为什么它没有在VisualStudio中命中断点。下面是AJAX脚本AJAX调用未命中异步处理程序中的断点,ajax,asp.net-core-2.0,razor-pages,Ajax,Asp.net Core 2.0,Razor Pages,我编写了一个在按钮按下事件中调用的快速AJAX脚本,该事件反过来调用asysnc处理程序从远程API中提取数据。我修改了同一个脚本来调用另一个非异步的处理程序,它工作得很好,我不知道为什么它没有在VisualStudio中命中断点。下面是AJAX脚本 $("#RunNewShodanQuery").click(function (d) { $.ajax( { type: "POST", async: true,
$("#RunNewShodanQuery").click(function (d) {
$.ajax(
{
type: "POST",
async: true,
url: "/Tools/Test?handler=UpdateResultsAsync",
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
error: function (jqXHR, exception) {
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
console.log(msg);
},
complete: function (res) {
console.log(res);
}
});
})
这是正在讨论的处理程序
public async Task OnPostUpdateResultsAsync()
{
ModelState.Clear();
foreach (Entry e in _context.Entries)
{
// TBI
}
// Update Date of Last Scan so as not to make needless API calls spamming refreshes
DateOfLastScan = DateTime.Now;
// Dispose of the client once we're done
client.Dispose();
}
我在另一个测试处理程序中放置了断点,并使用URL修改了上述AJAX,以指向新的测试处理程序,并在该处理程序中的断点上停止VS
public void OnPostTestHandler()
{
int seven = 5;
}
我目前不明白为什么VisualStudio没有在异步处理程序中命中断点。从浏览器中,我看到条目返回状态为200,并且它似乎正在执行处理程序代码,而不是在其中停止。任何建议都是非常受欢迎的。按照惯例,处理程序方法的名称是根据方案
OnPost[handler]Async
基于处理程序参数的值选择的
这意味着,对于postUpdateResultsAsync,处理程序名称是UpdateResults
,而不是UpdateResultsAsync
对于Razor页面,PageActionInvoker
将调用DefaultPageHandlerMethodSelector。选择Handlers
以选择处理程序
private List<HandlerMethodDescriptor> SelectHandlers(PageContext context)
{
var handlers = context.ActionDescriptor.HandlerMethods;
var candidates = new List<HandlerMethodDescriptor>();
// Name is optional, may not be provided.
var handlerName = GetHandlerName(context);
// The handler selection process considers handlers according to a few criteria. Handlers
// have a defined HTTP method that they handle, and also optionally a 'name'.
//
// We don't really have a scenario for handler methods without a verb (we don't provide a way
// to create one). If we see one, it will just never match.
//
// The verb must match (with some fuzzy matching) and the handler name must match if
// there is one.
//
// The process is like this:
//
// 1. Match the possible candidates on HTTP method
// 1a. **Added in 2.1** if no candidates matched in 1, then do *fuzzy matching*
// 2. Match the candidates from 1 or 1a on handler name.
// Step 1: match on HTTP method.
var httpMethod = context.HttpContext.Request.Method;
for (var i = 0; i < handlers.Count; i++)
{
var handler = handlers[i];
if (handler.HttpMethod != null &&
string.Equals(handler.HttpMethod, httpMethod, StringComparison.OrdinalIgnoreCase))
{
candidates.Add(handler);
}
}
// Step 1a: do fuzzy HTTP method matching if needed.
if (candidates.Count == 0 && AllowFuzzyHttpMethodMatching)
{
var fuzzyHttpMethod = GetFuzzyMatchHttpMethod(context);
if (fuzzyHttpMethod != null)
{
for (var i = 0; i < handlers.Count; i++)
{
var handler = handlers[i];
if (handler.HttpMethod != null &&
string.Equals(handler.HttpMethod, fuzzyHttpMethod, StringComparison.OrdinalIgnoreCase))
{
candidates.Add(handler);
}
}
}
}
// Step 2: remove candidates with non-matching handlers.
for (var i = candidates.Count - 1; i >= 0; i--)
{
var handler = candidates[i];
if (handler.Name != null &&
!handler.Name.Equals(handlerName, StringComparison.OrdinalIgnoreCase))
{
candidates.RemoveAt(i);
}
}
return candidates;
}
private List selectHandler(页面上下文)
{
var handlers=context.ActionDescriptor.HandlerMethods;
var候选者=新列表();
//名称是可选的,可能不提供。
var handlerName=GetHandlerName(上下文);
//处理程序选择过程根据几个条件考虑处理程序。处理程序
//有一个他们处理的已定义的HTTP方法,还可以选择一个“名称”。
//
//对于没有动词的处理程序方法,我们实际上没有一个场景(我们没有提供一种方法)
//如果我们看到一个,它将永远不会匹配。
//
//动词必须匹配(带有一些模糊匹配),如果
//有一个。
//
//过程如下:
//
//1.在HTTP方法上匹配可能的候选项
//1a.**在2.1中添加**如果1中没有匹配的候选项,则进行*模糊匹配*
//2.在处理程序名称上匹配1或1a中的候选人。
//步骤1:匹配HTTP方法。
var httpMethod=context.HttpContext.Request.Method;
对于(var i=0;i=0;i--)
{
var handler=候选者[i];
if(handler.Name!=null&&
!handler.Name.Equals(handlerName,StringComparison.OrdinalIgnoreCase))
{
候选人。RemoveAt(i);
}
}
返回候选人;
}
按照惯例,处理程序方法的名称是根据方案OnPost[handler]Async
基于处理程序参数的值选择的
这意味着,对于postUpdateResultsAsync,处理程序名称是UpdateResults
,而不是UpdateResultsAsync
对于Razor页面,PageActionInvoker
将调用DefaultPageHandlerMethodSelector。选择Handlers
以选择处理程序
private List<HandlerMethodDescriptor> SelectHandlers(PageContext context)
{
var handlers = context.ActionDescriptor.HandlerMethods;
var candidates = new List<HandlerMethodDescriptor>();
// Name is optional, may not be provided.
var handlerName = GetHandlerName(context);
// The handler selection process considers handlers according to a few criteria. Handlers
// have a defined HTTP method that they handle, and also optionally a 'name'.
//
// We don't really have a scenario for handler methods without a verb (we don't provide a way
// to create one). If we see one, it will just never match.
//
// The verb must match (with some fuzzy matching) and the handler name must match if
// there is one.
//
// The process is like this:
//
// 1. Match the possible candidates on HTTP method
// 1a. **Added in 2.1** if no candidates matched in 1, then do *fuzzy matching*
// 2. Match the candidates from 1 or 1a on handler name.
// Step 1: match on HTTP method.
var httpMethod = context.HttpContext.Request.Method;
for (var i = 0; i < handlers.Count; i++)
{
var handler = handlers[i];
if (handler.HttpMethod != null &&
string.Equals(handler.HttpMethod, httpMethod, StringComparison.OrdinalIgnoreCase))
{
candidates.Add(handler);
}
}
// Step 1a: do fuzzy HTTP method matching if needed.
if (candidates.Count == 0 && AllowFuzzyHttpMethodMatching)
{
var fuzzyHttpMethod = GetFuzzyMatchHttpMethod(context);
if (fuzzyHttpMethod != null)
{
for (var i = 0; i < handlers.Count; i++)
{
var handler = handlers[i];
if (handler.HttpMethod != null &&
string.Equals(handler.HttpMethod, fuzzyHttpMethod, StringComparison.OrdinalIgnoreCase))
{
candidates.Add(handler);
}
}
}
}
// Step 2: remove candidates with non-matching handlers.
for (var i = candidates.Count - 1; i >= 0; i--)
{
var handler = candidates[i];
if (handler.Name != null &&
!handler.Name.Equals(handlerName, StringComparison.OrdinalIgnoreCase))
{
candidates.RemoveAt(i);
}
}
return candidates;
}
private List selectHandler(页面上下文)
{
var handlers=context.ActionDescriptor.HandlerMethods;
var候选者=新列表();
//名称是可选的,可能不提供。
var handlerName=GetHandlerName(上下文);
//处理程序选择过程根据几个条件考虑处理程序。处理程序
//有一个他们处理的已定义的HTTP方法,还可以选择一个“名称”。
//
//对于没有动词的处理程序方法,我们实际上没有一个场景(我们没有提供一种方法)
//如果我们看到一个,它将永远不会匹配。
//
//动词必须匹配(带有一些模糊匹配),如果
//有一个。
//
//过程如下:
//
//1.在HTTP方法上匹配可能的候选项
//1a.**在2.1中添加**如果1中没有匹配的候选项,则进行*模糊匹配*
//2.在处理程序名称上匹配1或1a中的候选人。
//步骤1:匹配HTTP方法。
var httpMethod=context.HttpContext.Request.Method;
对于(var i=0;i