Monday, March 17, 2025

Atis ORM is now public

Atis ORM is a lightweight LINQ to SQL conversion system. I've been working on this ORM from past several years and an older version of this ORM is currently being used in a complex ERP system.

It's still under development but I have decided to make it public https://github.com/atis-orm/atis-orm.

Wednesday, May 17, 2023

Crystal Reports font problem in Exported PDF

So, we had this issue, that one of our Web App running on Server was generating a PDF file using Crystal Reports Export API. The Crystal Reports file had barcode fonts to generate barcodes. But the exported PDF was showing the normal Arial font instead of barcodes.

First I investigated that PDF file itself, whether barcode fonts are being embedded in the PDF file or not. So, I realized that instead of barcode fonts, it has Arial font only. So Crystal Reports export system was not embedding the Barcode Fonts during PDF file creation process.

Though we had already installed the fonts on the server, but the font was installed for the user which was logged in at the time of installation. So, I right clicked on the font file and clicked on Install for all Users. This resolved the issue and barcode fonts started to appear in PDF.

Note that this problem can occur for other reasons as well, for example, the fonts are secured and they are not allowed to be embedded. But in my case installing the fonts for all users resolved the problem.

Sunday, April 16, 2023

How to prevent authentication cookie to be renewed on background (polling) AJAX call in ASP.net core

I know that we should be using Web Sockets / SignalR for server side push notifications instead of polling. But I was looking for a quick solution to a simple problem where there is an AJAX call being made after every 5 seconds to server.

This web application is using cookie based authentication with SlidingExpiration. So, whenever any AJAX call is being made to the server, the cookie is renewed. Which is causing the user to be logged in for an indefinite time.

I wanted to have one specific API call to be marked in a way so that it should not renew the cookie. In this way, non-active user will be logged out automatically, even with continuous AJAX calls being made in the background.

We can use OnCheckSlidingExpiration event in cookie settings where we can check if our specific action is being called then we can simply set ShouldRenew to false.

    cookieOptions.Events.OnCheckSlidingExpiration = context =>
    {
        var controllerName = context.Request.RouteValues["controller"] as string;
        var actionName = context.Request.RouteValues["action"] as string;
        if (controllerName == "MyController" && actionName == "MyAction")
            context.ShouldRenew = false;
        return Task.CompletedTask;
    };

I didn't like this solution but unfortunately, I couldn't find any ActionFilterAttribute or any other way so that I can set some type of flag in the pipeline from action level, which can tell cookie event to not renew the cookie. It seems like the cookie events are the first thing in the pipeline that's executed, and action filters are executed later.