Posts

AUTOMATE: Restart router when the connection drops

Image
How good is your ADSL line? Does it drop every now and then? Does it have a terrible SNR and are you using a cheap router with bad noise reduction capabilities? Most importantly, does your router start working at full speed right after you restart it? Have you tried calling the provider and asked them to check the telephone line and couldn't they figure out what the problem is?

Well, I am having all these issues and my days are really slow because of this damned router doesn't do what it does best. And a high end router is not affordable right now.

As with everything in a software guys' life, I automated the process of restarting my fucking router with a python script. I have some photos being uploaded to google drive and I have installed this great cFosSpeed software which monitors my connection and has a great command line interface. Every router supports telnet connections so I created the following python script. It will contact cfosSpeed to get the upload rate, if it…

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…