Am working on Angular 8 with .Net Core, In my page if have two button "Search" and "Cancel Search". Is there a way to abort the Search button request when "Cancel Search" button is clicked? Scenario: Clicking on the Search button, the data is taking more time to be fetched from the Stored Proc and the user needs to iterate the search again. so he cancels the search and starts searching again. Cancelling the search should kill the session in the database too.
service.ts
Search(searchdata: any): Observable {
const url = ${this.apiUrl}/SearchData
;
return this.http.post<any>(url, searchdata).pipe(
tap(() => this.logger.log(`Search Data`)),
catchError(this.errorHandler.handleError<any>(""))
);
}
Controller
[HttpPost("SearchData")]
public async Task<IActionResult> SearchData([FromBody] SearchData searchData, CancellationToken token = default(CancellationToken))
{
var result = await _apiService.PostRequest<SearchResults[]>(
$"{_endpoint}/search/SearchData",
JsonConvert.SerializeObject(ruleInfo),
$"Error searching",
token: token,
timeout: TimeSpan.FromMinutes(10))
.ConfigureAwait(false);
return Ok(result);
}
API Controller
[HttpPost("SearchData")]
public async Task<IEnumerable<SearchResults>> SearchData([FromBody] SearchData searchData, CancellationToken tokenSource)
{
try
{
var result = await _searchService.SearchData(searchData, cancellationTokenSource);
return result;
}
catch (Exception ex)
{
throw ex;
}
}
the API Controller will be calling the Stored Procedure which will be running long for some scenarios.
I have to implement the Cancel Search button functionality for cancelling the Search and also kill the session in the Database. Is there a way to trigger the cancellationtoken of Search functionality from the CancelSearch button click event and if so will it kill the DB session?