Posts

Showing posts with the label Web API

API Security and OWASP Top 10 security details

Image
In last five years, using of technology made a big shift. One example is arising of API. Using API is now almost everywhere and it took place very fast because of it's flexibility, easy creation as well as implementation using a few clicks. World accepted API.  However, every good side has a hidden side and the same is true while we go with API implementation. Vulnerability is a nigh risk here. Creating API with proper validation, ensuring business logic properly meet all hidden loophole checks, and configuring API with right policies while implementing is BIG task and it requires right skills and experiences. Here is an easy diagram why attacker target API first. For standard web/mobile app development scenario, we are going through a standard process along with required tools and techniques which help us to test app and its implementation thoroughly and make vulnerability safe. However, for API implementation the same in false. We still running with lack of tools and implemen...

Publish WebAPI in Azure using Visual Studio

Image
 Microsoft always make your life easier. Publishing a WebAPI using Visual Studio is all about a couple of clicks. Before start, you must have a WebAPI working at your local and you must have a Azure subscription. Once build done, right click on the project and click on publish. At this stage, it identify what is the Resource Group, and API Management object is required to be fit in.  Next couple of screens are very simple and self explanatory.  In this stage, click on P ublish button to allow visual studio to publish your WebAPI. Now, you can check and test your WebAPI through Azure and see how it is working. Make sure all backend call are executing as expected.

405 Method Not Allowed - For Keyless entity types

Image
EF Core model allows keyless entity types, which can be used to carry out database queries against data that doesn't contain key values. There are never tracked for changes in the DataBase Context and therefore are never inserted, updated or deleted on the database. How to use this in your class. Let's say, you have a class named Share, you can place [Keyless] attributes on top of the class, and that's it! using Microsoft.EntityFrameworkCore; using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace AzureHostedApi {     [Keyless]     public class Share     {         [DisplayName("Share Code")]         [Required(ErrorMessage = "{0} is required")]         [StringLength(10, MinimumLength = 3,         ErrorMessage = "Share Code should be minimum 3 characters and a maximum of 10 characters")]         [DataType(DataType.Text)]  ...

.NET WebAPI calling Mongo DB

Image
 This is basic WebAPI project created using .NET 7.0 version and it makes call to MongoDB database collection sitting in Mongo Cloud. The DB configuration is in appsettings.json file. Below is the project structure - simple is the best :) You can create simple WebApI project using VS Studio 2022 on .NET 7.0 and then replace the code of individual pages from below. Please create the folders i.e. Models , Controller , and Services as shows in above picture  Please make sure to update DB configuration in appsettings.json according to your setup. The other important thing is to install MongoDB Driver, Core etc from Nuget Package. Page: AppSettings.json {   "MovieStoreDatabase": {     "ConnectionString": "mongodb+srv://m001-stu01-monb-basics@box.hongodb.net/test",     "DatabaseName": "video",     "DBCollectionName": "movieDetails"   },   "Logging": {     "LogLevel": {       "Default": "...

Core Web API issues Related to Mongo DB - IMongoCollection<> could not be found AND System.FormatException at MongoDB.Bson.Serialization.BsonClassMapSerializer

Image
 .NET Core and Mongo DB is a good bonding pair in Full Stack frame. Today, two issues I'm going to elaborate here and those two issues has been raised while developing Web API using .NET Core platform and use Mongo DB as backend. Web API will call the Mongo DB and fetch the record, specific record, and able to update the record as well. Simple and straight forward. Build is successful. However, when I try to run this and actually test in browser, get the following error. Obvious this occurred at start up. Below the error. Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'IMongoCollection<>' could not be found (are you missing a using directive or an assembly reference?) MVCCoreApi MVCCoreApi\Services\MovieService.cs One important note here, you should have MongoDb driver  installed at your end so that you can add  using MongoDB.Driver;  in your project and work with  IMongoCollection ...