ASP.NET Core equivalent of ASP.NET MVC 5’s HttpException

I implemented my own HttpException and supporting middleware which catches all HttpException‘s and turns them into the corresponding error response. A short extract can be seen below. You can also use the Boxed.AspNetCore Nuget package. Usage Example in Startup.cs public void Configure(IApplicationBuilder application) { application.UseIISPlatformHandler(); application.UseStatusCodePagesWithReExecute(“/error/{0}”); application.UseHttpException(); application.UseMvc(); } Extension Method public static class ApplicationBuilderExtensions … Read more

Why do I get “Cannot redirect after HTTP headers have been sent” when I call Response.Redirect()?

According to the MSDN documentation for Response.Redirect(string url), it will throw an HttpException when “a redirection is attempted after the HTTP headers have been sent”. Since Response.Redirect(string url) uses the Http “Location” response header (http://en.wikipedia.org/wiki/HTTP_headers#Responses), calling it will cause the headers to be sent to the client. This means that if you call it a … Read more

How do I get StatusCode from HttpRequestException?

Status code was passed as part of a string to HttpRequestException so that you cannot recover it from such exceptions alone. The design of System.Net.Http requires you to access HttpResponseMessage.StatusCode instead of waiting for the exception. http://msdn.microsoft.com/en-us/library/system.net.http.httpresponsemessage(v=vs.110).aspx If you are now following the Microsoft guide, make sure you understand clearly why it asks you to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)