Posts

Showing posts with the label .net-core

ITelemetryProcessor breaks dependency tracking

Image
Clash Royale CLAN TAG #URR8PPP ITelemetryProcessor breaks dependency tracking I have set up a custom ITelemetryProcessor for my .NET Core 2.1 Web API. I do not want HTTP status codes 400 or 401 to be displayed as error in Application Insights. The following class does this, but as soon as I use it SQL and HTTP client dependency tracking will no longer work: ApplicationInsights400IsOkProcessor public class ApplicationInsights400IsOkProcessor : ITelemetryProcessor { private ITelemetryProcessor Next { get; set; } /// <summary> /// Link processors to each other in a chain. /// </summary> /// <param name="next"></param> public ApplicationInsights400IsOkProcessor(ITelemetryProcessor next) { this.Next = next; } /// <summary> /// API Aufrufe mit Rückgabecode 400 und 401 sind keine Fehler /// </summary> /// <param name="item">Telemetry zum Verarbeiten</param> public void P...

.NET Core (2.1) web API controller accepting all that follows within the request url as parameter

Image
Clash Royale CLAN TAG #URR8PPP .NET Core (2.1) web API controller accepting all that follows within the request url as parameter What I have is a .NET Core 2.1 web API controller (in the following the TestController) that should generate redirects to other urls when receiving GET requests. Example: The controller is called like: http://localhost/api/v1/Test/somedir/somesubdir/filename.extension and it should return a redirect to https://example-domain.com/somedir/somesubdir/filename.extension My example controller for this question looks like: [Authorize] [Route("api/v1/[controller]")] public class TestController : ControllerBase { [HttpGet("{path}")] public async Task<IActionResult> Get(string path) { //path e.g. is somedir/somesubdir/filename.extension string prefix = "https://example-domain.com/api/v1/Other/"; //string path2 = HttpContext.Request.Path.Value.Replace("/api/v1/Test/", "/api/v1/Othe...

How to catch an exception and respond with a status code in .NET Core

Image
Clash Royale CLAN TAG #URR8PPP How to catch an exception and respond with a status code in .NET Core I am running a .Net Core Web API project. I have a startup file (below). In the Startup.ConfigureServices(...) method, I add a factory method that creates an instance of IFoo. I want to catch any exceptions that the IFooFactory throws and return a better error message with a status code. At the moment I getting a 500 Error with the exception Message. Can anyone help? Startup.ConfigureServices(...) public interface IFooFactory { IFoo Create(); } public class FooFactory : IFooFactory { IFoo Create() { throw new Exception("Catch Me!"); } } public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddScoped<IFooFactory,FooFactory>(); services.AddScoped(serviceProvider => { IFooFactory fooFactory = serviceProvider.GetService<IFooFactory>(); return fooFacto...

.net core Application is run with different port with electron.net with cross platrom

Image
Clash Royale CLAN TAG #URR8PPP .net core Application is run with different port with electron.net with cross platrom I've developed an application using .NET Core and Electron.NET and created one login form . .NET Core Electron.NET For login , I have created separate web API project and call the login API on login button click. web API When I call API from an application, Its give an error about "Cross-Origin", so I need to register an IP Address and Port in that API but right now I am facing an issue like .net core application is run on the different-different port each time. IP Address Port .net core While call sign-in in API from the window environment it gives me below port: 8001 While calling the same API from the Ubuntu it gives me port 35941 . So now I am facing an issue like, we have the different project for web API and it allows us to call web API on the specific port but due to each time different port generated by the electron.net, we can not call the ...

Angular5 + DotnetCore 2.1 - How to convert dateTime?

Image
Clash Royale CLAN TAG #URR8PPP Angular5 + DotnetCore 2.1 - How to convert dateTime? I have a problem handling date in angular, I got a datetime from server (using ASP.NET Core 2.1) like : "2018-07-29T06:31:41.57547" but actually I just need the date only without time like "2018-07-29". This caused my wont show the date in my form. Should I use AutoMapper to map all datetime to string first or could I just convert to date in my angular ? or any other solutions ? Did u try this from your api serverDate.ToString("yyyy-MM-dd"); – ershoaib 40 secs ago 1 Answer 1 Just convert it in Angular using DatePipe https://angular.io/api/common/DatePipe By clicking "Post Your Answer", y...

HttpPost does not get ContentLength from PostAsync request

Image
Clash Royale CLAN TAG #URR8PPP HttpPost does not get ContentLength from PostAsync request I have a unit test code that sends request to an HttpPost method. [Test] public async Task ValidateToken() { var content = new FormUrlEncodedContent(new { new KeyValuePair<string, string("test", "test") }; httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded")); var response = await httpClient.PostAsync("/api/token/1", content); Assert.AreEqual(HttpStatusCode.Accepted, response.StatusCode); } [Route("api/token")] public class MyController : BaseApiController { private readonly HttpRequest httpRequest; public MyController(IHttpContextAccessor httpContextAccessor) { httpRequest = httpContextAccessor.HttpContext.Request; } [HttpPost("{count}")] public async Task<IActionResult> Post(int count) { if...