Search This Blog

Thursday, June 17, 2021

How to interpret JWT token or Access token expiry in date time ?

 Use Online tool such as https://jwt.io/ which allows you to decode, verify and generate JWT.

You will find the decoded value in payload data section.

Copy the values of iat (issued at) or exp (expiry) and use the below link to convert the time 
https://koopar-tools.w3spaces.com/index.html

e.g: in the above example Token expiry is 1623945123 => Thu Jun 17 2021 21:22:03 GMT+0530 (India Standard Time)

Sunday, May 30, 2021

How to represent Azure Function in Microsoft threat modeling tool?

You can add your own stencil to the Azure template e.g I created a new stencil as below. You can also add some constraints or property to the Azure functions stencil. 



You can then add this stencil as target to the relevant threat types e.g as below.






Friday, May 28, 2021

How to run ASP.Net core MVC solution locally without deploying to Service Fabric Cluster

If you are working on ASP.net web application which is hosted in a Service Fabric Cluster, you might have come across the pain in debugging these application. Luckily there is an alternative to avoid the hassle in setting up service fabric development environment in the local machine. Below changes to your code in Program.cs file will help you debug your ASP.Net web application locally.


Program.cs file in ASP.net web application

Sunday, January 24, 2021

Console app that Formats JSON string

Console application that prints formatted JSON from a json string. "JValue.Parse(jsonString).ToString(Formatting.Indented)" can be used in you web application as well.


using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;

namespace ConsoleAppTryOut
{
    class Program
    {
        static void Main(string[] args)
        {
            string jsonString = "[{\"Question\":{\"QuestionId\":49,\"QuestionText\":\"Whats your name?\",\"Answer\":\"xyz\"}},{\"Question\":{\"QuestionId\":51,\"QuestionText\":\"Are you smart?\",\"Answer\":\"Yes\"}}]";

            Console.WriteLine(JValue.Parse(jsonString).ToString(Formatting.Indented));

            Console.Read();
        }
    }
}


The formatted output looks as below



Wednesday, November 6, 2013

Arrow key events not getting fired on combo box

Create a new Combo box class by inheriting from the base ComboBox. Below code explains how to.
You may come across such problems when you add combo box to another control like Data grid cell.



Saturday, October 26, 2013

Break points are not hitting in visual studio

If you have problem debugging your code, debug control not getting stopped at break point try the following. This is one of the solution and not the only solution. Also please be informed that your customized settings done on visual studio will be changed if you perform this action. You can also save your existing visual studio settings in file using the wizard before performing this action.

Close all open visual studio instances, then open a new visual studio instance. Click Tools --> Import and Export Settings... as shown below.









Please do let me know if you could resolve the issue.



Tuesday, April 12, 2011

The module "xyz.dll" was loaded but the call to DllRegisterServer failed with error code 0x80070005.

This error ocurs when you try to register a dll in a windows 7 or windows 2008 OS. This is because these OS uses UAC (user access control) concept. To execute "regsvr32" you have to execute it as a elevated command. To run the tool "regsvr32" follow these steps.

1. Click start.
2. Type "cmd" in the search text box. Command tool appears in the search result.
3. Right click on "CMD" and click "Run as Administrator". A User Account Control dialogue box appears asking you to allow the changes to be done. Click Yes.
4. In the command prompt type "Regsvr32 "dll path\xyz.dll"

Wednesday, January 19, 2011

Create Custom Genric List class

This article is about creating a custom List class. Suppose you want a List type called Employees which will hold employee class object in it. We can do it by defining a class of type generic List which is of type Employee.

Employee.cs

    public class Employee
    {
        int empId;
        string empName;
        string empDesig;

        public Employee()
        {
        }

        public Employee(int empId, string empName, string empDesig)
        {
            this.empId = empId;
            this.empName = empName;
            this.empDesig = empDesig;
        }

        public int EmpId
        {
            get { return empId; }
            set { empId = value; }
        }
        public string EmpName
        {
            get { return empName; }
            set { empName = value; }
        }
        public string EmpDesig
        {
            get { return empDesig; }
            set { empDesig = value; }
        }
    }


Now you can define your own Employee list type by inheriting Generic List<T> type which has type employee as parameter. Below is the code for the same.

Employees.cs

    public class Employees: List<Employee>
    {
        public MyList()
        {
        }

        public new void Add(Employee item)
        {
            base.Add(item);
        }

        public new IEnumerator<Employee> GetEnumerator()
        {
            return base.GetEnumerator();
        }

        public new Employee this[int index]
        {
            get { return this[index]; }
            set { this[index] = value; }
        }
    }

In the abouve example code function like Add, indexer are the basic implementation. You can have your own implementation.

Wednesday, January 5, 2011

Allow only numeric value in textbox

To allow only numeric value in textbox, the KeyPress event of the text box can be handled to achive it. You will just need to add the following code.

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)  
{
        if (!char.IsNumber(e.KeyChar) & (Keys)e.KeyChar != Keys.Back)
        {
              e.Handled = 
true;
         }
}