Posts

Create Azure Function and Read Values From Azure Queue

Image
What is Azure Functions Azure Functions is a serverless solution that allows you to write less code, maintain less infrastructure, and save on costs. Instead of worrying about deploying and maintaining servers, the cloud infrastructure provides all the up-to-date resources needed to keep your applications running. The following are a common,  but by no means exhaustive , set of scenarios for Azure Functions. If you want to... then... Build a web API Implement an endpoint for your web applications using the  HTTP trigger Process file uploads Run code when a file is uploaded or changed in  blob storage Build a serverless workflow Chain a series of functions together using  durable functions Respond to database changes Run custom logic when a document is created or updated in  Cosmos DB Run scheduled tasks Execute code on  pre-defined timed intervals Create reliable message queue systems Process message queues using  Queue Storage ,  Service Bus , or...

Read Azure Queue Storage from .Net Core Background Task

What is background tasks In ASP.NET Core, background tasks can be implemented as  hosted services . A hosted service is a class with background task logic that implements the  IHostedService  interface. How to create a background task Let's continue to add a new class called  WeatherDataBackgroundTask in the same solution that we created to make an entry to Azure Queue storage ( https://techabhimanyu.blogspot.com/2022/08/azure-storage-queue.html )  and try to read the queue data from this background task To make the class  WeatherDataBackgroundTask a background task, we need to inherit it from the class BackgroundService and need to implement the method  ExecuteAsync We need to run this application for always (as long as the explicit cancel is not requested), so that it can read all entries from the Azure queue storage. We can use  while (!stoppingToken.IsCancellationRequested) to achieve the same Let's create a queueClient to connect ...

Azure Storage Queue

Image
What is  Azure   Queue Storage  Azure Queue Storage is a service for storing large numbers of messages. You access messages from anywhere in the world via authenticated calls using HTTP or HTTPS. A queue message can be up to 64 KB in size. A queue may contain millions of messages, up to the total capacity limit of a storage account. Queues are commonly used to create a backlog of work to process asynchronously. Attributes of Azure Queue Storage Azure storage queue lives under a storage account (Azure storage account also supports blob, file share, queues, tables and disk) Within a storage account, you an have multiple queues Every single queue can have multiple messages The size of a message can't be more than 64 KB The URL format of a queue is  https:// <storage account> .queue.core.windows.net/ <queue> For example -  https://learnaboutazurestorage.queue.core.windows.net/add-weatherdata How to Create Azure Storage account and Azure Storage Queue Log...

Enabling CORS in .Net Core Web API

Image
  Cross-Origin Resource Sharing (CORS) Browser security prevents a web page from making requests to a different domain than the one that served the web page. This restriction is called the  same-origin policy . The same-origin policy prevents a malicious site from reading sensitive data from another site. Cross-Origin Resource Sharing  ( CORS ) is an  HTTP -header based mechanism that allows a server to indicate any  origins  (domain, scheme, or port) other than its own from which a browser should permit loading resources Cross Origin Resource Sharing  (CORS): Is a W3C standard that allows a server to relax the same-origin policy. Is  not  a security feature, CORS relaxes security. An API is not safer by allowing CORS. For more information, see  How CORS works . Allows a server to explicitly allow some cross-origin requests while rejecting others. Is safer and more flexible than earlier techniques, such as  JSONP . In this example -...

Web API Security in .Net6

Image
 What is Web API Security Web API Security is a mechanism to ensure that the APIs are not to be accessed without proper authentication and authorization. This is required to ensure that the APIs are not misused. Authentication is a mechanism to ensure that the user is a valid user and authorization to ensure that the user has all the right permission to access a method. Adding Authentication at Controller and Action Level We can do this by adding  [Authorize] attribute at the controller level. This ensures that all the method of this controller can only be accessed by an authenticated user. If we want to exclude a specific method from Authentication and Authorization process then we need to write  [AllowAnonymous] at the action method level. If we do not want to apply Authentication and Authorization to all the methods of a controller and want it to do for any specific method, then we can write [Authorize] attribute on the top of that method instead o...

Web API Using EF Core

Image
What is Web API  As the name suggests, is an API over the web which can be accessed using HTTP protocol. We can build Web API using different technologies such as Java, .NET etc.  Web API breaks the limitation of language. For example a web API written in .Net can be utilized by Java and vice verssa, because the request/response format of Web API is JSON which is understood by all language. For example, Twitter's  REST APIs  provide programmatic access to read and write data using which we can integrate twitter's capabilities into our own application. We can use tools like Fiddler, PostMan and Swagger for testing Web API .Net Core Web API -   Is an Ideal platform for building RESTful services. Is built on top of ASP.NET and supports ASP.NET request/response pipeline Maps HTTP verbs to method names. Supports different formats of response data. Built-in support for JSON, XML, BSON format. C...