Posts

How to create a .NET Core MVC File Uploader Module - Part 1

Image
Fine UploaderEver since I started developing websites, file/image uploading really gave me a hard time because I just couldn't figure out how to make the upload more generic and pluggable. After seeing Google/Facebook/500px♥ does it, I figured, it must be possible and should be simple. I always tend to over-complicate stuff. A prime example is this SO question (Adjusting dates in an array based on a start date) I asked a few days back. After a few tries, I came up with a solution. This is done using .NET Core MVC6 and You are free to steal this and modify according to your needs. (Give credits where necessary, be human)


So my requirements are simple:
To be able to upload files into a central file repositoryTo be able to select uploaded files and attach them to a postIf it's an image, show a previewTo be able to add metadata related to the file as we upload themTo be able to validate the said metadata before uploadingTo be able to plug it into any page without too much configura…

Token Authentication C# Console Application - Sample

How to use token authentication from a console application to call and Web API endpoint.

ASP.NET MVC Fine Grained Identity & Access Control - Part 3

In this series I will explain how I designed a generic claims based access control system ASP.NET MVC 5 with Identity 2.0.
In Part 1, I describe my approach and the initial database design. ASP.NET MVC Fine Grained Identity & Access Control - Part 1

In Part 2, I started laying foundation for the whole system with all the data models and a functional UI.

In this Part 3, I will start with most of the coding to make it work.

So far completed coding is in the GitHub repo: https://github.com/dirnthelord/ClaimsAuth

Note that, in part 2, I've mentioned the functionalities I want the system to have. In this post, I will complete all the core functionality so that I can directly edit the DB table values (using SSMS - SQL Server Management Studio) to test things out. I still need to create a UI for the super admins to easily manage permissions.

First off, lets grab all the Areas, Controllers and Actions in the system. These are what you going to lock down to certain groups.

I have po…

ASP.NET MVC Fine Grained Identity & Access Control - Part 2

Image
In this series I will explain how I designed a generic claims based access control system ASP.NET MVC 5 with Identity 2.0. In Part 1, I describe my approach and the initial database design. ASP.NET MVC Fine Grained Identity & Access Control - Part 1

In this Part 2, I will start laying foundation for the whole system with all the data models and a functional UI.



So far completed coding is in the GitHub repo: https://github.com/dirnthelord/ClaimsAuth

First, I need to decide what functionality the UI should have.
As a super admin, I need to be able to view the application resources from the UI. Add a description and search them.As a super admin, I need to be able to manage all the users in the system.As a super admin, I need to be able to manage global permissionsAs a super admin, I need to be able to manage user groups and group permissionsAs a super admin, I need to be able to manage user groups and group permissions
So, these are the list of things I need to be able to do withi…

Why You Should Always Use Decorator Pattern

Image
Life get easier when you have more reusable decorators and a good dependency injector.

Years before I choose this programming/engineering career, I always wondered, how can I make something better? How can I make it work faster or efficiently? I'm no backyard scientist or whatever so basically, it was all just thinking and speculating. Running simulations in my head, kinda. Once I started programming, I was interested in making machines talk. "Knight Rider" was my inspiration. Talking cars!!! And then, I was super interested in learning all the mechanisms behind AI. I'm a fan of AI, taking over the world or not, I always wanted to build one. For some fucked up reason, I still can't even get a simple neural-net working. Sure, copy pasting works but what's the point. I suck at math, may be that's the reason. And, as with everything in life, we come up with excuses to either postpone something or completely give up and look the other way. I just never, comp…

Custom Error Messages in ASP.NET MVC

Image
Even when you have custom errors mode on,
and Have all the custom error pages setup, like the following..

<customErrors mode="On" defaultRedirect="~/Error" redirectMode="ResponseRewrite"> <error statusCode="403" redirect="~/403" /> <error statusCode="401" redirect="~/401" /> <error statusCode="404" redirect="~/404" /> <error statusCode="409" redirect="~/409" /> <error statusCode="500" redirect="~/500" /> </customErrors>

You even set Response.TrySkipIisCustomErrors = true; on your error handler to get rid of those ugly IIS default error pages.
/// <summary> /// Returns a Not Found error. /// </summary> [HttpGet, Route("404")] [AllowAnonymous] public ActionResult NotFound() { Log.E…

Beautiful Code Makes Life Beautiful

Image
This is the Part 1 of my post series about good code.

Part 2 : Why I Always Choose Decorator Pattern

There are two kinds of software developers. Those who write crappy code and those who write beautiful code. I'm sure if you are a fan of beautiful code, you'd agree with me. Those who don't agree and those who think I'm stupid, read on.

Everyone has to start somewhere, right? Us, developers, when we start creating our first program, most of us don't really know what design patterns are or don't understand them or why we should be using them. We just jump right into writing code. And then we hit run and the code works. So fucking great!

Atleast, that's what I thought before I start making a living out of my code. Organizations need readable, maintainable, bug free, well commented and well understood code. Imagine we were tasked with adding a new functionality to assembly code. I don't even know assembly because that shit is ugly. Sure, we can talk to the …