Posts

c# - Self referencing loop detected (Solved 2-Ways)

Getting around C# self-referencing loop exception Sometimes we come across this kind of error when building web apps. This kind of error occurs when we have multiple navigational properties in the model and EF cannot parse the relational objects. The best way to overcome this is to use the Newtonsoft library to parse it to a string, use a DTO object or anonymous types to pass the data required or set this in the Global.asax file to ignore reference loop handling GlobalConfiguration . Configuration . Formatters . JsonFormatter . SerializerSettings . Re ‌ ​ ferenceLoopHandling = ReferenceLoopHandling . Ignore ; The Model class If you have a product model class that has a navigational property Category, it would be hard for EF to parse the results of both properties to the view. Take a product class for example: public class Product{    public int Id { get; set; }    public string Name{ get; set; }    public decimal Price{ get; set; } ...

Visual Studio 2017 Live Share

Image
Visual Studio Introduces Live Sharing Collaboration is key when it comes to working on a project with teams. Visual studio has improved drastically over the years. Visual studio 2017 allows developers to collaborate on projects at real-time. This is not like GIT of TFS, it is something that would eventually be an improvement and would make work easier and faster for developers. Imagine when working on a project and you share a portion of your code to a fellow developer to monitor, track your progress and even correct your mistakes at real-time. Cool right? Yeah!!! Hail Visual Studio. Check out this video to know more about Visual Studio Live Sharing More Features Visual Studio 2017 also has more new great features that enhances the productivity of developers around the globe. The features are: You can now navigate, write, and fix your code fast Quickly find and fix bugs Use version control to collaborate efficiently And lots more... Visit visual studio w...

.Net Image Upload in Cloudinary

Image
Cloudinary In C# Cloudinary is the market leader in providing a comprehensive cloud-based image management solution. Cloudinary is being used by tens of thousands of web and mobile application developers all around the world, from small startups to large enterprises. We are here to cover your every image-related need. Cloud storage is the way If you still write code to save files or images in a folder in your production/development server or even in the database, you are in trouble. I just hope you are aware of the consequences of doing that. I built a class that allows you to upload, remove and download images from cloudinary which can be used in your web projects too. But, before you dive into coding, you have to register on cloudinary website and get an API key for development. The Code before we create the class, install the cloudinary package via nugget using System.Collections.Generic; using System.Web; using CloudinaryDotNet; using Cloudinar...

Google reCAPTCHA using HttpClient in ASP.NET

Image
Introduction reCAPTCHA   is a free service that protects your site from spam and abuse. It uses advanced risk analysis techniques to tell humans and bots apart. With the new API, a significant number of your valid human users will pass the  reCAPTCHA  challenge without having to solve a  CAPTCHA . Building The Code Before you start, visit this link  https://www.google.com/recaptcha/intro/index.html  and click on the Get  reCAPTCHA  button and follow the steps. Let's Get started  Step 1 : Create a class or a method in your controller and add the code below.             public async Task<string> GetRecaptcha()         {             var response = HttpContext.Current.Request["g-recaptcha-response"];             const string secretKey = "your secret key";       ...

Solved: Jwt Authentication in Asp.Net Web Api And Mvc

Jwt in Asp.Net Web API And MVC Introduction Token based security is trending everywhere in today’s security architecture. There are different token providers out there, but the one people are more familiar with is the JWT token. The token identifies a user. For example, your ID card could be used as a token. It identifies who you claim to be. The Id card would contain information like: ·         Firstname ·         Lastname ·         Age ·          Title The JSON Web Token The JSON Web Token contains some header information, a signature, and the token’s claims. In plain text, the claims might look like this: { "Name":"John doe", "UserId":5, "Email":"johndoe@gmail.com", "Role":"Boss" } The token header is used to specify some other things like signature algorithm, expiration date, the name of the issuer, and a few other attributes. Using Jwt In Asp.Net Web API The JwtA...