Dijkstra’s algorithm is a greedy algorithm which in each step finds the best solution and when we sum those solutions we find the best solution in general. The algorithm doesn’t work for edges with negative weights so in this case is used another algorithm which is called Bellman–Ford algorithm.

Let’s create an example weighted graph and explain how the algorithm works.

Let’s say we want to find the shortest path from vertex A to vertex F.

Initially we assign infinite value to all vertices as we don’t know the shortest distance to them. We assign 0 to starting vertex A as distance to self is 0.

We take the starting vertex A and we mark it as visited and then we observe all connected vertices and if the value of the visited vertex plus weight of the edge to the neighbor vertex is smaller than current value of the neighbor vertex then we update the neighbor vertex’s value with the weight of the edge plus value of the current visited vertex.

So in our example the value of A is 0 and the distance to B is 1.0. The current value of B is infinity.

**(0 + 1.0) < infinity, then we update the value of B to 1.0**

The value of A is 0 and the distance to C is 2.0. The current value of C is infinity.

**(0 + 2.0) < infinity, then we update the value of C to 2.0**

The next step is to chose which vertex to visit. The key point here is to take vertex with minimum value from unvisited vertices. In our case this is vertex B which has value 1.0 and it is less than the value of vertex C which is 2.0. From implementation point of view this is the point where we use priority queue. We enqueue vertices in a priority queue and then when we need the vertex with min value we just call dequeue and we get the minimum vertex.

So now we are on vertex B. We repeat the same operations here. We need to check the values of all **unvisited** neighbor vertices and update them if the current value + edge weight to neighbor vertex is smaller than neighbor vertex’s value. Be careful not to perform this operation to the visited neighbors.

So in our case B is connected to A and D. As A is already visited we will observe only D.

D’s current value is infinity, B’s current value is 1.0 and distance to D is 6.5.

**(1.0 + 6.5) < infinity, then we update the value of D to 7.5**

In the next step we take the vertex with min value from unvisited vertices. In our case this is vertex C

C (2.0) < D (7.5)

C has the following neighbors: A, E, D. From those neighbors only D and E are unvisited so we only observe them.

D has a value of 7.5. C has value of 2.0 and distance to D is 0.5.

**(2.0 + 0.5) < 7.5, then we update the value of D to 2.5**

E has value of infinity. C has value of 2.0 and the distance to E is 10.5

**(2.0 + 10.5) < infinity, then we update the value of E to 12.5**

In the next step we take the unvisited vertex with minimum value which is D.

D(2.5) < E(12.5)

D has the following neighbors: C, E, F. From those neighbors only E and F are unvisited so we only observe them.

E has value of 12.5. D has value of 2.5 and the distance to E is 2.0

**(2.5 + 2.0) < 12.5, then we update the value of E to 4.5**

F has value of infinity, D has value of 2.5 and the distance to F is 0.5

**(2.5 + 0.5) < infinity, then we update the value of F to 3.0**

Next we take the vertex with minimum value from unvisited vertices which is F.

F(3.0) < E(4.5)

F has two neighbors: D and E. From those neighbors only E is unvisited so we observe only E.

E has value of 4.5. D has value of 3.0 and the distance to E is 1.0

**(3.0 + 1.0) < 4.5, then we update the value of E to 4.0**

We have only one vertex which is unvisited, we visit vertex E. As all neighbors of E are already visited we are done with the algorithm at this stage. All vertices are visited and they have assigned values.

Note that in this graph example we had to always update the values of neighbor vertices but take into account if:

**(current vertex’s value + distance from current to neighbor) > neighbor’s value **

we don’t update the neighbor vertex’s value.

So looking into the initial graph where we applied Dijkstra’s algorithm we can say that the shortest path from A to F is: A–> C–> D–> F and the total distance is 3.0.

Let’s have a look how we can implement Dijkstra’s algorithm with C# code. We we will use a priority queue which we explained in one of the previous articles here https://paircoders.com/2021/04/19/heap-priority-queue/

First we will create a Vertex class which will represent our vertices in the graph described above

```
public class Vertex : IComparable<Vertex>
{
// We could have defined Vertex<T>
// as generic to store any data inside
// it, as you would probably do in
// real world, here we miss it for
// simplicity
//public T Value { get; set; }
public string Name { get; set; }
public decimal Weight { get; set; }
public bool IsVisited { get; set; }
public Vertex Parent { get; set; }
public Vertex(string name)
{
this.Name = name;
}
public int CompareTo(Vertex other)
{
if (this.Weight < other.Weight)
return -1;
else if (this.Weight > other.Weight)
return 1;
else return 0;
}
}
```

We will keep a reference to the parent which last updated the current vertex’s value in order to be able to backtrack the shortest path for any given vertex.

Next we will create class Dijkstra

```
public class Dijkstra
{
private List<Vertex> vertices;
private decimal[][] adjMatrix;
public Dijkstra(decimal[][] graph, List<Vertex> vertices)
{
if (graph.Length != vertices.Count)
{
throw new InvalidOperationException("Mismatch between graph and vertices");
}
this.adjMatrix = graph;
this.vertices = vertices;
}
}
```

We use adjacency matrix to represent the graph, basically the two most popular approaches to represent a graph are adjacency matrix and adjacency list, you can learn more about this topic here https://www.geeksforgeeks.org/graph-and-its-representations/

Next we will add a method to Dijkstra class called ApplyDijkstra which will apply the algorithm.

```
private void ApplyDijkstra(int source)
{
PriorityQueue<Vertex> pq =
new PriorityQueue<Vertex>(PriroityQueueType.Min);
// Initialize all vertices with infinite value
foreach (var v in this.vertices)
{
v.Weight = decimal.MaxValue;
}
// Source vertex's distance to self is zero
this.vertices[source].Weight = 0.0m;
pq.Enqueue(this.vertices[source]);
while (pq.Count() > 0)
{
// get the vertex with minimum wight
// from unvisited vertices to process
var minVertex = pq.Dequeue();
minVertex.IsVisited = true;
var minVIndex = vertices.IndexOf(minVertex);
// Go trough all unvisited neighbors
// and try to update their weight
for (var i = 0; i < adjMatrix[minVIndex].Length; i++)
{
// if weight is zero no connection between two vertices
if (this.adjMatrix[minVIndex][i] == 0.0m) continue;
// we are interested only in unvisited vertices
if (this.vertices[i].IsVisited) continue;
// calculate neighbor's weight by
// adding current weight and distance to the neighbor
// from current vertex
var calculatedWeight = adjMatrix[minVIndex][i] + minVertex.Weight;
// if calculated distance/weight is less then
// we found better path so update the neighbor's weight
if (calculatedWeight < this.vertices[i].Weight)
{
this.vertices[i].Weight = calculatedWeight;
this.vertices[i].Parent = minVertex;
// Add neighbor to the queue to process it later
pq.Enqueue(this.vertices[i]);
}
}
}
}
```

With this method we traverse all vertices in vertices list and looking at the graph matrix we update the values of each vertex. Next we will add public method which takes source and destination parameters, applies the algorithm and then backtracks the shortest path from distance to source and last it returns an information about the shortest path and total distance.

```
public string PrintShortestPath(string sourceName, string destinationName)
{
// We miss guard clauses for simplicity
var sVert =
vertices.First(v => v.Name == sourceName);
int source =
vertices.IndexOf(sVert);
var dVert =
vertices.First(v => v.Name == destinationName);
int destination =
vertices.IndexOf(dVert);
// Calculate all vertices' weights
ApplyDijkstra(source);
var destinationVertex = vertices[destination];
// Using stack to backtrack the path from
// destination to source by iterating parents
Stack<Vertex> backTrackShortestPath = new Stack<Vertex>();
bool pathExists = false;
while (destinationVertex != null)
{
if (destinationVertex.Name == sourceName)
{
backTrackShortestPath.Push(destinationVertex);
pathExists = true;
break;
}
backTrackShortestPath.Push(destinationVertex);
destinationVertex = destinationVertex.Parent;
}
if (!pathExists)
{
return $"No path exists from vertex:{source} to vertex:{destination}";
}
StringBuilder shortestPath = new StringBuilder();
var currentWeightArrow = "";
while (backTrackShortestPath.Count > 0)
{
var currentVertex = backTrackShortestPath.Pop();
shortestPath.Append($"{currentWeightArrow}({currentVertex.Name})");
currentWeightArrow = "--->";
}
shortestPath.AppendLine("\nTotal " +
$"distance from vertex:{sourceName} " +
$"to vertex:{destinationName} is " +
$"{vertices[destination].Weight}");
return shortestPath.ToString();
}
```

Next let’s construct the graph we explained above and use the code above to find the shortest path

```
static void Main(string[] args)
{
List<Vertex> vertices = new List<Vertex>
{
new Vertex("A"),
new Vertex("B"),
new Vertex("C"),
new Vertex("D"),
new Vertex("E"),
new Vertex("F")
};
decimal[][] graph = {
new[] { 0.0m, 1.0m, 2.0m, 0.0m, 0.0m, 0.0m },
new[] { 1.0m, 0.0m, 0.0m, 6.5m, 0.0m, 0.0m },
new[] { 2.0m, 0.0m, 0.0m, 0.5m, 10.5m, 0.0m },
new[] { 0.0m, 6.5m, 0.5m, 0.0m, 2.0m, 0.5m },
new[] { 0.0m, 0.0m, 10.5m, 2.0m, 0.0m, 1.0m },
new[] { 0.0m, 0.0m, 0.0m, 0.5m, 1.0m, 0.0m }
};
var dijkstra = new Dijkstra(graph, vertices);
var shortestPath =
dijkstra.PrintShortestPath("A", "F");
Console.WriteLine("The shortest path:");
Console.WriteLine(shortestPath);
Console.ReadLine();
}
```

The result in the console is:

The algorithm’s time complexity is

`O(E Log V)`

E – number of edges

V – number of vertices.

With this we conclude our explanation about Dijkstra’s algorithm. You can read more about the topic here:

https://www.programiz.com/dsa/dijkstra-algorithm

https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/

]]>The properties of heap described above makes it easy to be implemented with an array data structure and most commonly the heap is implemented with an array data structure. Let’s see how we would show a min heap with an array.

Based on the above representation we can define several formulas in order to detect parent or child nodes of a given node based on the index of an array. Given n is the index of an array then:

**Parent node index = (n – 1) / 2**

Example: Take 5th index which is 32, so (5 – 1) / 2 = 2 which is 30 the parent node.

**Left child index = (2 * n) + 1**

Example: Take 2nd index which is 30, so (2 * 2) + 1 = 5 which is 32 the left child.

**Right child index = (2 * n) + 2**

Example: Take 2nd index which is 30, so (2 * 2) + 2 = 6 which is 52 the right child.

Heapifying is an operation which rearranges the elements of the heap so it satisfies the conditions of min or max heap based on the heap type. This operation is performed after adding or removing a node from the heap or/and priority queue although in priority queue we have only enqueue and dequeue based on the priority of the elements compared to regular queue.

This operation starts from first index of non-leaf node whose index is given by n / 2 – 1 where n is the size of the array. Each root, left child and right child is compared and if they don’t satisfy the heap property the nodes are swapped. The operation is repeated until we reach the root node with index 0. Let’s see with example how we will heapify a tree which does not satisfy min heap properties.

When we add item to the heap/priority queue we add it as last item to the tree and then we heapify the tree as described above.

When we dequeue / remove item from the tree we swap the item to be removed with the last item in the tree, the rightmost node. Then we remove the last item which became the item we wanted to remove after we made a swap in previous step. Finally we heapify the tree in order to satisfy the heap properties.

Let’s see how we can implement priority queue in C#. First we will define an enum which will define the queue type.

```
public enum PriroityQueueType
{
Min,
Max
}
```

Then we will define a PriorityQueue class and implement it’s methods.

```
public class PriorityQueue<T> where T : IComparable<T>
{
private List<T> items;
private PriroityQueueType PriroityQueueType;
public PriorityQueue(PriroityQueueType priroityQueueType)
{
this.items = new List<T>();
this.PriroityQueueType = priroityQueueType;
}
}
```

We use generic class where the type should implement IComparable in order to compare the items when we implement priority queue operations. Next let’s implement heapify method.

```
private void Heapify(int index)
{
int count = items.Count;
int largestOrSmallest = index;
int leftIndex = 2 * index + 1;
int rightIndex = 2 * index + 2;
//check if current node is larger or smaller than left child based on the queue type
//if true then assign left child index to variable largestOrSmallest in order to track it
if (leftIndex < count &&
((PriroityQueueType == PriroityQueueType.Min
&& items[largestOrSmallest].CompareTo(items[leftIndex]) > 0)
|| (PriroityQueueType == PriroityQueueType.Max
&& items[largestOrSmallest].CompareTo(items[leftIndex]) < 0)))
{
largestOrSmallest = leftIndex;
}
//check if largestOrSmallest node is larger or smaller than right child based on the queue type
//if true then assign right child index to variable largestOrSmallest in order to track it
if (rightIndex < count &&
((PriroityQueueType == PriroityQueueType.Min
&& items[largestOrSmallest].CompareTo(items[rightIndex]) > 0)
|| (PriroityQueueType == PriroityQueueType.Max
&& items[largestOrSmallest].CompareTo(items[rightIndex]) < 0)))
{
largestOrSmallest = rightIndex;
}
//if one of the child is larger or smaller than the root then we need to swap them
if (largestOrSmallest != index)
{
T temp = items[largestOrSmallest];
items[largestOrSmallest] = items[index];
items[index] = temp;
//As we swapped the root item with one of the children we need to recrsively heapify the subtrees
Heapify(largestOrSmallest);
}
}
```

Heapify method is the code representation of the heapify operation visually described above.

Next we will implement enqueue method where we add an item to the end of the queue and then we start heapifying the tree starting from index n/2-1 where n is the count of the elements in the queue.

```
public void Enqueue(T item)
{
if (items.Count == 0)
{
items.Add(item);
}
else
{
items.Add(item);
for (int i = items.Count / 2 - 1; i >= 0; i--)
{
Heapify(i);
}
}
}
```

We will implement helper method DeleteNode which will delete a node from the heap by given index of the element. We will afterwards use this method to easily implement Dequeue operation of priority queue. Delete method follows the visual steps described earlier in this article.

```
private void DeleteNode(int index)
{
if(index > items.Count-1) throw new IndexOutOfRangeException();
T temp = items[index];
items[index] = items[items.Count - 1];
items[items.Count - 1] = temp;
items.RemoveAt(items.Count - 1);
for (int i = items.Count / 2 - 1; i >= 0; i--)
{
Heapify(i);
}
}
```

Using this method to implement dequeue operation is really easy we just call it with index 0 which is the top item of the queue.

```
public T Dequeue()
{
if (items.Count == 0)
throw new InvalidOperationException("The priority queue is empty");
T topItem = items[0];
DeleteNode(0);
return topItem;
}
```

Finally we implement Peek which is just returning the top item.

```
public T Peek()
{
T topItem = items[0];
return topItem;
}
```

It is worth mentioning the algorithm complexity of binary heap and priority queue.

Peek – O(1)

Enqueue – O(log n)

Dequeue – O(log n)

With this we conclude the explanation of heap and priority queue.

You can read more about this topic here:

https://www.geeksforgeeks.org/priority-queue-set-1-introduction/

https://www.programiz.com/dsa/priority-queue

The purpose is to share little pieces of helpful practices and tricks that will make your work better and more pleasant.

Do you prefer listening to music while working?

If so – what kind of music?

Let me share my preferences on that topic.

I’ve felt that there are **two **working ** mood types**.

is when we have to come up with a solution for some complex problem, or when we have to think of a design problem, or we need to decide on the correct architectural approach, or solve a tricky puzzle, or find out an appropriate algorithm.

Basically – we have to involve a high level of concentration and a fair amount of thinking.

Let’s call that mood type – **Le Penseur** (*in French*),

or **The Thinker**.

is when we know what needs to be done, the approach has been discovered, we’ve already done the thinking work and now we need to implement it.

Let’s call that – **The Worker** mood type.

I pick my music based on the mood type I am currently at.

The most productive I am in **The Thinker** mood while I listen to more * calm *and

During this mood, I prefer to keep the volume at lower levels!

On the other hand, when I am in **The Worker** area I find it most appropriate and boosting my velocity when I play more dynamic, more… fast, and sometimes kind of aggressive music, which energizes me and pushes me to do the work and to enjoy it!

In those moments I play some **metal **songs with a fast rhythm, for example, “*Pantera*“, “*Sepultura*“, “*Soulfly*“, often I listen to death metal bands like “*In Flames*“, “*Edge Of Sanity*“, etc.

I also often play something more electronic like “*The Prodigy*” or even some psytrance – my favorite here is “*Infected Mushroom*“.

And on some occasions, the classical music helps here as well – like *Vagner *or *Beethoven*, or even something more modern like *Yann Tiersen*.

Often the volume is in higher levels on that mood.

Here is actual research on the topic, which kind of syncs with my feelings and conclusions:

“Kellogg reviews a vast body of research to extract a few notable findings. Among them is the role of background noise, which seems to fall on a bell curve of fecundity: High-intensity noise that exceeds 95 decibels disrupts performance on complex tasks but improves it on simple, boring tasks — noise tends to raise arousal level, which can be useful when trying to stay alert during mindless and monotonous work, but can agitate you out of creative flow when immersed in the kind of work that requires deliberate, reflective thought.”

https://www.brainpickings.org/2014/08/25/the-psychology-of-writing-daily-routine/

Of course, the music picks depend on your personal preferences, but the main connection is that:

**The Thinker** needs something **calm and harmonious**.**The Worker** wants **dynamics and energy**.

The purpose is to share little pieces of helpful practices and tricks that will make your work better and more pleasant.

Upgrade your working environment by surrounding yourself with easily accessible **helpers**. **Print **out some useful (*for you*) **content **that can be used as a quick reference.

Of course, you can store all of those **cheat sheets** in electronic format somewhere on your hard drive (or URL bookmarks).

However, I would advise you to have some **on paper.**

That way you will not search for the file and disturb your inertion.

The physical version has a *psychological aspect *as well. You know that a piece of particular knowledge is exactly somewhere in the space around you and you can have a look at it for a second. So you are going to make references to those “* extensions of your brain*” in an absolutely natural and even semi-unconscious way.

Let me share with you some **example **resources:

- https://www.bigocheatsheet.com/ –
**Algorithms complexities**cheat sheet. - https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet – Basic
**GIT**commands. **SQL Server:**

– https://cheatography.com/davechild/cheat-sheets/sql-server/ : Basics.

– https://tableplus.com/blog/2018/08/ms-sql-server-data-types-cheatsheet.html : Data types

– https://www.guru99.com/sql-cheat-sheet.html : More complete list.- https://cheatography.com/kstep/cheat-sheets/http-status-codes/ –
**HTTP status codes**. - https://docs.microsoft.com/en-us/visualstudio/ide/default-keyboard-shortcuts-in-visual-studio?view=vs-2019 –
**Visual Studi**keyboard shortcuts. - https://cheatography.com/davechild/cheat-sheets/regular-expressions/ –
**Regular expressions**.

The purpose is to share little pieces of helpful practices and tricks that will make your work better and more pleasant.

You know the feeling when your machine needs to be restarted and then you have lo run all your programs again.

Or when you come back from a holiday. Or some updates that needs to happen. Or something else which needs reset of the current state of your environment.

You can actually do something about that annoying process and automatically run everything you need.**First**, create a ** batch file **(.bat for Windows or shell script (.sh) for MAC OX and Linux) on some easily accessible place.

**Then** include in the** script** all of the programs you want to run at once, like so:

```
@echo off
:: Open a particular solution
start C:\Projects\Other\Playground\Playground.sln
:: Open other programs like Outlook, Notepad, etc.
start outlook
start notepad++
:: SQL Server Management Studio
start ssms
:: Open Chrome and browse some useful pages
start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://stackoverflow.com/
start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://paircoders.com/
:: You can even update your local Git repo with the latest changes
cd C:\Projects\GIT\KOCreate && git.exe pull
@echo on
```

**Finally*** run the batch* and let it do the job.

So the best thing you can do is to read their thoughts and advices.

Here is a sample list of *my *top 10 blogs to follow. Pick whatever is applicable for your preferences.

*URL*: http://blog.cleancoder.com/*About*: Coding good practices, rules, standards, guidance, clean coding.

*URL*: https://martinfowler.com/*About*: Architecture, design, methodologies.

*URL*: https://www.hanselman.com/blog/*About*: Microsoft technologies – .NET, .NET Core, geeky stuff, software development and IT stuff.

*URL*: https://davidwalsh.name/*About*: Scripting – JavaScript, PowerShell, etc.

*URL*: https://hackernoon.com/tagged/software-development*About*: Wide variety of software development topics.

*URL*: https://gunnarpeipman.com/*About*: Microsoft – .NET/.NET Core, Azure.

*URL*: https://davidwalsh.name/*About*: .NET latest news and tips.

*URL*: https://cloudblogs.microsoft.com/sqlserver/*About*: SQL Server latest news.

*URL*: https://particular.net/blog*About*: Vries topics in the software development world.

*URL*: https://www.geeksforgeeks.org/featured-articles*About*: Algorithms, data structures, scripts, etc.

This is a workshop organized by “*Software University*” / aka *SoftUni */ (Sofia, Bulgaria) which took place on 21-st of Jan, 2021.

The content which I covered here is about some good practices for software developers, a time management technique, the root OOP principles, SOLID, Composition over Inheritance, Design Patterns and Software Architecture Patterns overview.

It is in Bulgarian language, but I promise to write separate blog posts in English for those topics… and more

]]>I always google it when I setup a new Dev environment.

If you are also working with Visual Studio and its built in GIT integration, then you have noticed that the remote branches shown under the Branches tree in the Team Explorer, are only increasing. Even some of the branches have been deleted from the remote server that have not been reflected to the tree.

This can be fixed by an easy configuration.

Open Team Explorer, then go to Home -> Settings -> Repository Settings and set the “Prune remote branches during fetch” to

Then press

BehaviorSubject example

The BehaviorSubject is one of the 4 variants of RxJS Subjects (*“a special type of Observable which shares a single execution path among observers”*).

The BehaviorSubject keeps the last emitted value from the observable object and can be returned to the subscribers.

One useful usage of it is to be populated with the response data returned from an HTTP request.

This can be done like this (*Angular code snippet*):

```
import { HttpClient } from '@angular/common/http';
import { BehaviorSubject } from 'rxjs';
import { tap } from 'rxjs/operators';
import { IMySubject } from '@interfaces';
export class SubjectExampleService {
private _subject: BehaviorSubject<IMySubject> = new BehaviorSubject(null);
public subject$: Observable<IMySubject> = this._subject.asObservable();
constructor(private _http: HttpClient) {
}
getTestData() {
return this._http
.get('https://my-api-url/getMeTheData')
.pipe(
tap((response: IMySubject) => this._subject.next(response))
);
}
}
```

The above code snipped represents the creation of an Observable service.

We are encapsulating our logic, hide the BehaviorSubject, and return a public observable object to which the consumers can subscribe and always have the latest emitted response value from the service.

Note that adding a value to the BehaviorSubject is done by *this._subject .next(response)*.

Update BeahviorSubject

Occasionally you can fall into a scenario where you would need to update the Subject manually. For instance, if there is another operation happening which updates some property of our *IMySubject* object from the given example above.

In that case we can add another method in the *SubjectExampleService* service and update the BehaviorSubject from within with the following syntax:

```
updateSubjectData(theChangedProp: string) {
this._subject.next({
...this._subject.value, mySpecialProperty: theChangedProp
});
}
```

We call **this._subject.next** and pass as a first argument the value of the current object. The second parameter is the name of the property to be changed and the new value.

Recently I experienced a situation where one of the apps I am working on stopped working.

There were no new deployments to the server, nor configuration or database-related changes.

When requesting the web site immediately receive – 500 internal server error.

OK, HTTP error code 500 means something’s wrong with the server:

“*The server encountered an unexpected condition that prevented it from fulfilling the request.*“

So I began to think of the possible reasons and started to check things on the server:

- Is the server started
- Are the IIS and all the needed app pools working properly
- Check the application logs
- Are there multiple servers, and if so:
- are all of them functioning correctly (IIS, firewall accesses, needed services, etc.)
- is the load balancer working properly – check its logs
- try to connect to every single server separately

- Check for expired certificates (this will generate a different error code as a response, but still it can lead to HTTP 500 with combination with other configurations, so it’s worth checking that)
- Check the application pool users – their password could be expired or their access rights modified
- Check for events logged in the Event Viewer (Windows users)
- Check the server logs
- For IIS (On Windows Server), the default/standard location of the log files is under %SystemDrive%\inetpub\logs\LogFiles (C:\inetpub\logs\LogFiles)

The problem and the according resolution could be in any of the above points.

But if your system infrastructure looks good, the system is working fine, you do not have application logs, and no useful information in the Event Viewer like it was in my case, then the key point was the last one in the list.

So I examined the IIS logs.

You can find the following information for every request:

- date
- time
- s-ip
- cs-method
- cs-uri-stem
- cs-uri-query
- s-port cs-username
- c-ip
- cs(User-Agent)
- cs(Referer)
**sc-status****sc-substatus****sc-win32-status**- time-taken

The red ones are important.

In my case this values were (*sc-status*: **500**, *sc-substatus*: **19**, *sc-win32-status*: **5**).

You can find the statuses and corresponding sub-statuses meaning here:

https://support.microsoft.com/en-us/help/943891/the-http-status-code-in-iis-7-0-iis-7-5-and-iis-8-0

And the information of the Win32 statuses can be found here:

https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes?redirectedfrom=MSDN

My readings (respectively what helped me with the problem) were that there was “Access is denied.” error logged from IIS. So that means the Application Pool user doesn’t have access to the application folder. Which causes the termination of the request and the response with 500.

]]>