Skip to content

Instantly share code, notes, and snippets.

@dumbledad
Created July 28, 2016 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dumbledad/9d3f70b5621eb004e5f8758c4dcdc3f4 to your computer and use it in GitHub Desktop.
Save dumbledad/9d3f70b5621eb004e5f8758c4dcdc3f4 to your computer and use it in GitHub Desktop.
Comparing the response written in ASP.Net Core with the one actually received
Startup.cs
var responseText = new ExceptionResponse(statusCode, ex).ToString();
await context.Response.WriteAsync(responseText);
responseText is set to:
"{\"ExceptionType\":\"SecurityTokenExpiredException\",\"Message\":\"IDX10223: Lifetime validation failed. The token is expired.\\nValidTo: '07\\/23\\/2016 02:03:48'\\nCurrent time: '07\\/28\\/2016 14:20:17'.\",\"StackTrace\":\" at Blah.Startup.<>c.<Configure>b__6_1(AuthenticationFailedContext context) in D:\\\\Users\\\\me\\\\Source\\\\Repos\\\\ServerSideCode\\\\Blah\\\\Startup.cs:line 118\\r\\n at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.<HandleAuthenticateAsync>d__1.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.<InitializeAsync>d__48.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\\r\\n at Blah.Startup.<>c.<<Configure>b__6_0>d.MoveNext() in D:\\\\Users\\\\me\\\\Source\\\\Repos\\\\ServerSideCode\\\\Blah\\\\Startup.cs:line 59\",\"StatusCode\":401}"
But the caller gets this response body:
System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at AuthenticationHarness.MainPage.<TestApi_Click>d__18.MoveNext():
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment