Category: .NET

Databindings - small values treated as 0s

Today, I encountered an interesting problem with WinForms. In the application, NumericUpDowns (shown below) were used with small values e.g. 0.00001 etc. However, after we refreshed the panel, the value was being set to the default value. Digging further into the problem it turned out that the default Microsoft DataBinding converter was unable to convert

Continue Reading

How to use - (dash) in the ASP.NET MVC call?

ActionName attribute can be used:

 

Continue Reading

How to override MongoDB connection details in appsettings.json on Azure

It is actually pretty simple to override the connection settings in Azure. If you manage your connection inside the appsettings.json:

Then in Azure you should define these in Application Settings -> App settings. Seperate the layers by ":" (semi-colon). For example: Key: MongoConnection:ConnectionString Value: mongodb://admin:abc123!@localhost. Similarly, the database (key) MongoConnection:Database value: YourDb

Continue Reading

Extracting Username and Password from Basic Authentication

Basic authentication is one of the most fundamental ways in which authentication can be performed. It does not require multiple calls and is very easy to learn. In this article, I will present how to use C# (usually with WCF) to extract basic authentication credentials from the request. Step 1 - Understanding Basic Authentication Whenever

Continue Reading

Set background color for all buttons in WPF

Hehe, simple enough thing, but took long enough. You need to use resources to do it.

In there you can define styles:

It is simple enough to read: apply it to buttons. Property: Background set the value to whatever color you like.

Continue Reading

Lists of Lists in C# - if one is updated, all are updated.

I was doing an assessment for university regarding password cracking. They say that experience is something that cannot be learnt. Never that notion has been more true than today when I was attempting to create a list of lists: List<List<string>>. I had "virtually" unbounded memory, but I had to make sure that I could maximise

Continue Reading

Serializing Anonymous DataMemeber

I've been working win MVC Web API and encountered an annoying problem. It does not, by default serialise anonymous data members.

When you try to serialise this kind of data you get this beautiful exception:

Converting anonymous type to a string also caused exception. But there is also JavaScriptSerializer:

Now using getter,

Continue Reading

Useful Linear Trendline Class in C#

I've searched and searched trying to find a simple class to calculate a slope and intercept from a set of points. Here is the outcome, but I probably modify it to use LINQ rather then loops

Continue Reading

Footer from database in MVC ASP.NET

I've been struggling for a while to find a sensible way of getting the footer. Well... This is where partial views come useful. There are several ways to solve this problem. I've created a controller:

In the Shared folder I've added _FooterPartial.cshtml and in the layout this line:

It worked so awesome.

Continue Reading

Partial View not being published

I encountered a bit of a problem today. I've added a partial view manually to the project (i.e. it wasn't generated by the VS). To my annoyance, when I deployed the application to the test server the *.cshtml was not copied. After a bit of digging around, I found the problem. It turned out that

Continue Reading