Showing posts with label .NET Core. Show all posts
Showing posts with label .NET Core. Show all posts

Monday, April 16, 2018

GCP .Net Core Error Reporting

If use Log, it will log duplicate, so just throw exception, code below is throw exception with response 500 and exception class.

//Startup.cs After this

app.UseGoogleTrace();

app.UseExceptionHandler(
 options =>
 {
     options.Run(
     async context =>
     {

         context.Response.Headers.Add("Access-Control-Allow-Origin", "*"); //Allow Origin
         context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
         context.Response.ContentType = "application/json";
         var ex = context.Features.Get<IExceptionHandlerFeature>();
         if (ex != null)
         {
             var err = JsonConvert.SerializeObject(ex.Error);
             await context.Response.WriteAsync(err).ConfigureAwait(false);
         }
     });
 }
);

//Before this 
app.UseMvc();

----------------

try
{
    return Ok(result);
}
catch (Exception ex)
{
    throw ex;
}

Tuesday, March 27, 2018

.Net Core MemoryCache


  • IMemoryCache is Sticky Session, store in web server (Route all to the same Server)
  • Distributed Cache is Non-sticky Session, design for web farm.
  • CacheItemPriority.NeverRemove is cache priority

https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory

Monday, August 7, 2017

AWS Lamda

  • Service that lets you run code without managing servers (server-less)
  • Execute your code when needed and scales automatically. (no charge when your code not running)
  • Included Server and OS maintenance, auto scaling,  code monitoring and logging (FOC)
  • Support Node.js, Java, C# and Python.
  • It can run your code in response to events. E.g. Data Processing trigger for Amazon S3 or Amazon DyanamoDB
  • It can build Serverless applications. (only concern your code)
  • Outsider call Lambda thru API Gateway
  • Lambda can be custom authorization  at API Gateway
Step to create Lambda Project in VS2017


1) Need to Install AWS Extension



2) Deployment



3) API Gateway



.NET Core


  • Open Source
  • Cross-platform (Linux, MAC, Windows) framework for building modern cloud-based web applications (UI and API) using .NET
  • ASP.NET Core MVC = MVC + Web API + Web Pages
  • It can run on IIS or Self-hosted