I'm currently struggling with CreatedAtRoute, below are the details.
Desired solution in the future
Return object and URI in location header linking to endpoint GetGlobalSettings.
Current situation and problem
I have the following POST endpoint for resource creation which returns CreatedAtRoute like this return CreatedAtRoute(nameof(GetGlobalSettings), result.Data);
The route set in the location header should link to the endpoint with this method head:
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<GlobalSettingDto>> GetGlobalSettings()
With this I always get the following exception:
System.InvalidOperationException: No route matches the supplied values.
at Microsoft.AspNetCore.Mvc.CreatedAtRouteResult.OnFormatting(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor.ExecuteAsyncCore(ActionContext context, ObjectResult result, Type objectType, Object value)
at Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor.ExecuteAsync(ActionContext context, ObjectResult result)
at Microsoft.AspNetCore.Mvc.ObjectResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultAsync(IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
HEADERS
=======
Content-Type: application/json
:authority: localhost:5001
:method: POST
:path: /api/v1/GlobalSettings
:scheme: https
Accept: text/plain
Accept-Encoding: gzip, deflate, br
Accept-Language: de,de-DE;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
Host: localhost:5001
Referer: https://localhost:5001/swagger/index.html
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36 Edg/91.0.864.48
DNT: 1
Origin: https://localhost:5001
Content-Length: 768
sec-ch-ua: " Not;A Brand";v="99", "Microsoft Edge";v="91", "Chromium";v="91"
sec-ch-ua-mobile: ?0
sec-fetch-site: same-origin
sec-fetch-mode: cors
sec-fetch-dest: empty
I have API-versioning active, so I also tried the CreatedAtRoute-call like this:
var routeValues = new { version = "1.0" };
return CreatedAtRoute(nameof(GetGlobalSettings), routeValues, result.Data);
But this still throws the same error.
In your case, you should use CreatedAtAction:
return CreatedAtAction(nameof(GetGlobalSettings), routeValues, result.Data);
Regarding the difference between CreatedAtAction and CreatedAtRoute, you can see this thread.
Related
System.InvalidOperationException: An identity cannot be extracted from this request.
This generally indicates that the OpenIddict server stack was asked to validate a token for an endpoint it doesn't manage.
To validate tokens received by custom API endpoints, the OpenIddict validation handler (e.g OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme or OpenIddictValidationOwinDefaults.AuthenticationType) must be used instead.
at OpenIddict.Server.OpenIddictServerHandlers.ValidateAuthenticationDemand.HandleAsync(ProcessAuthenticationContext context)
at OpenIddict.Server.OpenIddictServerDispatcher.DispatchAsync[TContext](TContext context)
at OpenIddict.Server.OpenIddictServerDispatcher.DispatchAsync[TContext](TContext context)
at OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandler.HandleAuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
at Microsoft.AspNetCore.Authorization.Policy.PolicyEvaluator.AuthenticateAsync(AuthorizationPolicy policy, HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
HEADERS
Accept: */*
Host: localhost:7174
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
:method: GET
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IlYyUERaNl9RUjRfNFo0Q1VMUkUwWFdRRU1KNFVDT0VGSjNDQldTQUQiLCJ0eXAiOiJhdCtqd3QifQ.eyJzdWIiOiJwb3N0bWFuIiwic29tZS1jbGFpbSI6InNvbWUtdmFsdWUiLCJvaV9wcnN0IjoicG9zdG1hbiIsImNsaWVudF9pZCI6InBvc3RtYW4iLCJvaV90a25faWQiOiI3NGE3ZGNlMC1kNjJkLTRmZjQtYjg1MS1kMjRjN2E1OGIwNTEiLCJzY29wZSI6ImFwaSIsImV4cCI6MTY3MjIxMjQzMywiaXNzIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6NzE3NC8iLCJpYXQiOjE2NzIyMDg4MzN9.bls8ceNA9bU-xr1-9huV4LDqifX7KDn8E1bqGPGeeWh9ePeN1mYnywFC6lPVls8OtCmtm1v9iTnnfaoZ3r2v_IoKahl727B4QD8AkKpy_8ExiBBECtX9HqDid3w0c8dYS1Rka2xyh5mcKJzlqNlSucNbRqj7Hu8wisizV89K45qmWBsZTIsBqJOR5DKDjVzAEmAvjccD8Hb9kjF6lSiis2E7x41YO0dB4ugc5gEm1huEI44bps7qj9V2mQ70EcNi74KgK3Y57JsityV1Oqjv14gour2jjvccATtLhOtNisUfbw10jPlRj3AT1XiHDjjIhR5pb0z6XTJRblpmNt8wNQ
Referer: https://localhost:7174/swagger/index.html
sec-ch-ua: "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-fetch-site: same-origin
sec-fetch-mode: cors
sec-fetch-dest: empty
Does anyone know about this? Please tell me the solution
I have a dotnet core web project in which I have added this javascript
$trigger.on('click', function () {
const $button = $(this);
const resortId = $button.data('resortId');
$.post(url, { resortId: resortId }, function (response) {
etc...
});
});
The id is being passed correctly and is passed to the following controller method
[HttpPost]
[Route("wishlist/add")]
public JsonResult Add()
{
var response= _repository.Add(Request, HttpContext.Session);
return Json(response);
}
Which makes use of this bit of code
private static int GetId(HttpRequest request)
{
var form = request.Form;
int.TryParse(form["resortId"], out var resortId);
return resortId;
}
This seems to be where the code is failing
var form = request.Form; (Line 82)
Which to me is pretty innocuous!
This code works perfectly in my local setup, however when it sits on our staging server it doesn't work!
This is my full stack trace
------->
Message. "Incorrect Content-Type: "
Inner Exception.
""
StackTrace.
" at Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm()
at Microsoft.AspNetCore.Http.DefaultHttpRequest.get_Form()
at myproject.GetResortId(HttpRequest request) in Repository.cs:line 82
at Add(HttpRequest request, ISession session) in Repository.cs:line 31
at myproject.Controllers.Controller.Add() in Controller.cs:line 28
at lambda_method(Closure , Object , Object[] )
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)"
<-------
I have attempted to send the request using the jQuery ajax call instead of post so that I can explicitly state the content type, but this does not fix the issue.
I don't think it's important but there isn't an SSL certificate on this server (I was originally seeing a 405 response and wondered if this was why).
It's a classic "Works on my machine" situation, but I'm not sure how to further debug this.
Update
I have now refactored this to make use of a new object
Controller
[HttpPost]
[Route("wishlist/add")]
public JsonResult Add(WishListAddRequest request)
{
etc...
}
This gets the collection from the session and updates it with the item passed to the controller.
I now get a 405 response from the server on Staging and it works absolutely fine from my local machine.
Update 2
This serves as an answer to my particular problem although it isn't especially helpful to anyone else facing the issue.
I refactored the methods into html forms and posted these to the controllers removing the need for the JavaScript.
I did try to add an SSL certificate to the Staging website to rule out any issues there but ran into network-related problems.
I suspect that because the website has redirect rules pushing http requests to https on a server without SSL, my Ajax calls were falling foul of CORS and if I could prove that I would add an answer to the question.
I have an ASP.NET web site that access Google Drive using the .NET API v3. I followed the .NET Quickstart to create credentials and generate a token. The redirect_urls section of the JSON credential file looks like this...
"redirect_uris": [
"http://127.0.0.1/authorize/",
"http://127.0.0.1/authorize",
"https://127.0.0.1/authorize/",
"https://127.0.0.1/authorize"
],
This all works fine locally. When I debug the site, it pops up the Google oAuth screen, and asks me to authenticate. Once done, the site works fine, and the pages that access Google Drive can do so.
I now want to deploy to a staging site, so created new oAuth credentials, using the same details as before, but with the site's domain instead of 127.0.0.1. However, when I deploy the site, any attempt to load a page that accesses Google results in a time-out.
The event viewer on the server shows the following error (sensitive data obfuscated)...
System.Net.HttpListenerException (5): Access is denied.
at System.Net.HttpListener.AddPrefixCore(String registeredPrefix)
at System.Net.HttpListener.AddAllPrefixes()
at System.Net.HttpListener.Start()
at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.StartListener()
at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.ReceiveCodeAsync(AuthorizationCodeRequestUrl url, CancellationToken taskCancellationToken)
at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.AuthorizeAsync(String userId, CancellationToken taskCancellationToken)
at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(Initializer initializer, IEnumerable`1 scopes, String user, CancellationToken taskCancellationToken, IDataStore dataStore, ICodeReceiver codeReceiver)
at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(ClientSecrets clientSecrets, IEnumerable`1 scopes, String user, CancellationToken taskCancellationToken, IDataStore dataStore, ICodeReceiver codeReceiver)
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToPendingTasks(Task task)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderRootComponentAsync(Int32 componentId, ParameterView initialParameters)
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.CreateInitialRenderAsync(Type componentType, ParameterView initialParameters)
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.RenderComponentAsync(Type componentType, ParameterView initialParameters)
at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c__11`1.<<InvokeAsync>b__11_0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.ViewFeatures.StaticComponentRenderer.PrerenderComponentAsync(ParameterView parameters, HttpContext httpContext, Type componentType)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.PrerenderedServerComponentAsync(HttpContext context, ServerComponentInvocationSequence invocationId, Type type, ParameterView parametersCollection)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.RenderComponentAsync(ViewContext viewContext, Type componentType, RenderMode renderMode, Object parameters)
at Microsoft.AspNetCore.Mvc.TagHelpers.ComponentTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<RunAsync>g__Awaited|0_0(Task task, TagHelperExecutionContext executionContext, Int32 i, Int32 count)
at MyWebSite.Areas.General.Pages.Areas_General_Pages__Host.<ExecuteAsync>b__14_1() in C:\PathToWebSite\Areas\General\Pages\_Host.cshtml:line 24
at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.SetOutputContentAsync()
at MyWebSite.Areas.General.Pages.Areas_General_Pages__Host.ExecuteAsync() in C:\PathToWebSite\Areas\General\Pages\_Host.cshtml:line 6
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
I almost looks as if it's tried to pop up the oAuth page in a browser window on the server (which it won't manage, as there won't be a desktop associated with the user that runs IIS), and then times out waiting for someone to use that page. I could be wrong there, but if I'm right, I don't understand why it's trying to do this, as the whole point of creating credentials for a web application is that the person authenticating will not be on the server. However, I could be completely wrong with this assumption anyway!
The site is written using Blazor, but I don't think that's relevant, as I added an MVC controller as a test, and had exactly the same issue.
Anyone any idea why this is happening, and what I can do about it? Thanks.
If you are using the code in that quickstart, then it won't work in a web app. The code there is for a desktop app, and uses your browser to open the oAuth screen.
That page really doesn't make this clear, I picked this up from this comment on a GitHub issue. To quote (spelling mistakes included!)...
GoogleWebAuthorizationBroker.AuthorizeAsync is for iinstalled applicatons. Its going to try and open the authorization web browser on the server which is not going to work.
Your going to need something like Web applications (ASP.NET MVC)
However, the code in that link is for MVC, and I don't know if it will work with Blazor, as auth is a whole new ball game there. If you read the previous comment in that GitHub issue, you'll see the suggestion that you perform user auth in a standard ASP.NET Core part of the app, then passing the IGoogleAuthProvider into Blazor.
Hope that helps, even if it isn't what you wanted to hear!
I'm trying to create a folder on an Online SharePoint with the site url https://example.sharepoint.com/MySite
I really don't care anything about SharePoint lists, but I can't find any information towards a SharePoint API which hides this implementation detail from the consumer, nor any documentation which anticipates my needs well enough to tell me what I need to do, so I am struggling to work with the Lists.
At present, I just want to simply list whatever lists exist on my site. My site has some minimalistic content, so I expect in a world were everything has lists, there should be some lists involved and I should be able to somehow list them.
I have the following code:
using (ClientContext context = _authenticationManager.GetContext())
{
Web web = context.Web;
context.Load(web.Lists, lists => lists.Include(list => list.Title, list => list.Id));
context.ExecuteQuery();
foreach (List list in web.Lists)
{
_logger.LogInformation(list.Title);
}
}
I've been able to use the debugger and the console to confirm the AuthenticationManager is successfully generating an authentication token.
When the code executes, context.ExecuteQuery(); results in the following error:
[14:49:48 INF] Successfully requested new access token resource example.sharepoint.com for user someuser#somemail.foo <s:SharepointOrderContractExtractor.Clients.AuthenticationManager>
[14:49:48 ERR] An unhandled exception has occurred while executing the request. <s:Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware>
System.Net.WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at SharePointOrderContractExtractor.Clients.Client.CreateFolder(String folderName) in C:\projects\SharepointOrderContractExtractor\SharepointOrderContractExtractor\Clients\Sharepoint\Client.cs:line 34
at SharePointOrderContractExtractor.Services.SharePointService.CreateDestination(List1 orderNumbers) in C:\projects\SharepointOrderContractExtractor\SharepointOrderContractExtractor\Services\SharepointService.cs:line 128 at SharePointOrderContractExtractor.Services.SharePointService.CollectForAsync(List1 orderNumbers) in C:\projects\SharepointOrderContractExtractor\SharepointOrderContractExtractor\Services\SharepointService.cs:line 95
at SharePointOrderContractExtractor.Services.SharePointService.FetchContractsAsync(FileUploadModel uploadModel) in C:\projects\SharepointOrderContractExtractor\SharepointOrderContractExtractor\Services\SharepointService.cs:line 51
at SharePointOrderContractExtractor.Controllers.V1_0.SharePointController.Upload(FileUploadModel uploadModel) in C:\projects\SharepointOrderContractExtractor\SharepointOrderContractExtractor\Controllers\V1_0\SharepointController.cs:line 48
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Logged|12_1(ControllerActionInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
What am I missing and/or doing wrong?
How can I correct this?
With thanks to #arconaut for his question in the comments:
It seems the Authentication Manager only uses the domain, not the full URL in order to authenticate.
While my site URL was set to https://example.sharepoint.com/MySite, it should have been https://example.sharepoint.com/sites/MySite.
(I think I dropped "sites" from the configuration while trying to follow some documentation which may not have matched my version of Salesforce.)
In our project we have an HttpClient for outgoing connection with a strict timeout, and previously, I dealt with the timeout situation like all the tutorials suggested: by catching the TaskCanceledException. And it worked. But since recently (can't say the exact time, but about a month), the timeout started to cause the OperationCanceledException.
System.OperationCanceledException: The operation was canceled.
at System.Net.Http.HttpClient.HandleFinishSendAsyncError(Exception e, CancellationTokenSource cts)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
<buisness-logic traceback>
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at System.Threading.Tasks.ValueTask`1.get_Result()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at NSwag.AspNetCore.Middlewares.SwaggerUiIndexMiddleware`1.Invoke(HttpContext context)
at NSwag.AspNetCore.Middlewares.RedirectToIndexMiddleware.Invoke(HttpContext context)
at NSwag.AspNetCore.Middlewares.SwaggerDocumentMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
It's not a big problem to change all the catches to OperationCanceledException, but I'd like to know why? Does anybody know why HttpClient could switch the exception? I deploy the application locally using the VS2019 16.4.3 and IIS express. Net core 2.2
I found it.
https://github.com/dotnet/corefx/issues/33957
Basically, in case of short timeouts there is a race condition that can cause OCE to happen. What it means is "we do not really know what exactly happen, and we do not care, so you shouldn't too".