Below you will find pages that utilize the taxonomy term “HowTo”
Blog
Azure App Configuration with .NET Full Framework
This post on using App Configuration using .NET Full Framework was based on a contribution by Steven Hack.
My last post Azure App Configuration: an introduction received a lot of good feedback. And one of those pieces of feedback was a question if it’s also possible to use App Configuration if you’re using Full Framework.
The short answer: yes, this is possible!
For the slightly longer answer: keep reading 🤓
Blog
Azure App Configuration: an introduction
Azure App Configuration is a powerful way to manage and store application configuration on a central location. Integrating it into for instance ASP.NET (Core) is pretty straightforward. This post gives you an introduction to Azure App Configuration and a simple example of how to integrate it in ASP.NET Core.
Creating an Azure App Configuration 🆕 Of course there are several ways to create a specific resource in the Azure Portal. One of the simplest is to go to the portal, open up App Configuration and click the Add button.
Blog
Creating a custom JsonNamingPolicy
Probably there’s no need for me to say why .NET Core 3.0 is a big deal. There are enough articles on that. For a great write-up see Announcing .NET Core 3.0.
From the inception of the .NET Core project, we’ve added around fifty thousand .NET Framework APIs to the platform. .NET Core 3.0 closes much of the remaining capability gap with .NET Framework 4.8.
Introducing .NET 5
Next to adding this massive amount of .
Blog
HowTo: Call an API with cookie authentication from a Logic App
Calling an API from a Logic App is pretty straightforward. You open up the Logic App Designer and add an HTTP Action. Specify the method to use and the URI you want to call and you’re good to go!
When the API you want to call uses Cookie Authentication, this seems pretty straightforward too. After all, the HTTP Action has an Authentication property you can set. However, this property doesn’t include Cookie authentication.
Blog
HowTo: invite AAD user with Microsoft Graph
One of the time consuming tasks we’re facing at my current assignment is inviting users to our Azure Active Directory tenant. Especially since we (used to) do this in the Azure Portal. We’re using Azure Active Directory B2B to which external users are invited as guests. We investigated using Microsoft Graph to automate this process. Since there’s several things to take into account when implementing this, here’s a quick HowTo.
Blog
Unable to remove (native) app registrations in Azure Active Directory
While cleaning up the app registrations in my Azure Active Directory, I ran into two applications I couldn’t delete since the ‘Delete’ button is not clickable. I’ve had this happen for both application types: both Web app/API and Native.
It’s actually pretty simple to enable removing these app registrations: make sure the application is not Multi-tenanted. *
* Designates whether users in external organizations are allowed to grant your app access to data in their organization’s directory.
Blog
Getting Bootstrap to work on Windows Phone 8
There are a couple of websites I manage that use Twitter Bootstrap*. These websites are fully responsive and work well on all devices. Or actually, almost all devices. The wrapping of columns in a container on a Windows Phone doesn’t work the way you’d want it out of the box. Windows Phone interprets device-width as the actual resolution size. Other mobile browsers use what the manufacturer (or browser vendor) has decided is the optimal viewport width.
Blog
HowTo: sign out of Visual Studio Online (when deleting cookies won’t help)
When you have more than one Microsoft Account that you use regularly, you might recognize the scenario where your Visual Studio keeps you signed in to Visual Studio Online… with the wrong account. You keep getting messages that you don’t have access rights. Restarting Visual Studio, rebooting and even clearing all (Visual Studio) cookies doesn’t help. Here’s a quick fix:
Open Visual Studio Open the Visual Studio web browser (under View, Other Windows, Web Browser) Go to Visual Studio Online Click sign out You should be good to go now!
Blog
How to add Next and Previous buttons to Twitter Bootstrap tabs
Just a quickie today: when working with Twitter Bootstrap tabs, like I am in my ASP.NET MVC 4 project, you might want to add Next and Previous buttons on the tabs to create something of a Wizard. Here’sa step by step overview of how I did this:
Add an ID to all the ListItem elements that are used for the tab navigation. For instance:
<ul class="nav nav-tabs" id="myTab"> <li><a href="#example" data-toggle="tab" id="xmpl">Example</a></li> .
Blog
Debugging JavaScript with Visual Studio in an ASP.NET MVC 4 application
When debugging JavaScript in an ASP.NET MVC (4) application, it is not always enough to uncheck the ‘Disable script debugging’ checkboxes under ‘Tools’ – ‘Internet Options’ – ‘Advanced’ – ‘Browsing’. JavaScript inside a Razor view (a cshtml file) cannot be debugged from Visual Studio. To debug your JavaScript, move it to a separate .js file and link to that file from your Razor view. This way, breakpoints set in the JavaScript will be hit and you can debug from Visual Studio.
Blog
How To: Call a generic method with a runtime type
Problem:
Developing a generic class that maps datasets, datatables and datarows from a legacy system to my domain model, I ran into an issue. I wanted to call a generic method with a runtime type. Lets say the method looked like this: public string DoSomething<T>(string param). Because I use reflection to iterate properties on a type, the type of the properties was dynamic and only known at runtime. I wanted to do something like this:
Blog
Enable preview in Visual Studio 2012 after Update 1
After installing Visual Studio 2012 Update 1, my Visual Studio stopped opening files in preview mode when I clicked them in the Solution Explorer. This setting seems to have changed with the installation of Update 1. To re-enable opening files clicked (once) in the Solution Explorer in Preview mode, go to ‘Tools’ – ‘Options’ – ‘Environment’ – ‘Tabs and Windows’.
There, check the box under ‘Preview Tab’ – ‘Single-click opens files in the preview tab in:’ – ‘Solution Explorer (Alt + click to avoid previewing)’.
Blog
How To: Create an ActionLink with a Twitter Bootstrap icon in MVC4
Twitter Bootstrap is a… “Sleek, intuitive, and powerful front-end framework for faster and easier web development.” One of the nice things in Bootstrap is you can use icons from Glyphicons. To use these, you can simply use this markup <i class="icon-fire"></i> to get a nice fire icon.
Translating this into an ActionLink styled as a button in an MVC4 application would look something like the following:
@Html.ActionLink("<i class="icon-fire"></i> Invent fire", "fire", new { @class = "btn" }) Unfortunately, this renders as follows:
Blog
Microsoft Touch Mouse, Visual Studio (2012) and scrolling
My Microsoft Touch Mouse stopped scrolling in Visual Studio on my Windows 8 machine some time ago. Because this kills productivity, I wanted to fix the problem. After trying some things I found that the problem only occurred when I ran Visual Studio as Administrator. Searching a bit further I found this bug to be added to Microsoft Connect. I found a workaround for the problem:
Go to the location where you have Microsoft Mouse and Keyboard Center installed Open up the properties of ipoint.
Blog
HowTo: Have Visual Studio always run as administrator on Windows 8
In my previous post about being unable to access the iis metabase I wanted my Visual Studio to ‘Run as Administrator’ on my Windows 8 machine. I only managed to get this working for the pinned taskbar icon and not for items in the jumplist or for items you open by double clicking them. The solution to check the box ‘Run as Administrator’ on the compatibility tab of the file properties for devenv.
Blog
Documents.Open returns null, running Word automation under ASP.NET on x64
When building an ASP application that generates Word documents, it was working fine on the local machine: A Windows XP installation with Office 2007. When we deployed it to windows 2008 (64 bit) and Word 2007 we saw that Documents.Open returned null. Other than this, there are no exceptions.
The code that returned the error (simplified):
Application app = new Application(); Document doc = app.Documents.Open(ref name); As it turns out, a 64 bit system stores temporary files in C:\Windows\Sys\WOW64\config\system\profile\Desktop folder.
Blog
HowTo: Save a file from Silverlight using the SaveFileDialog
Saving a file from Silverlight using the SaveFileDialog, added in Silverlight 3, is easy. If you’re used to desktop development however, you might find yourself getting a SecurityException with the message ‘File operation not permitted. Access to path ‘xxx’ is denied.’. Here’s why:
In desktop development, you’re used to getting a filename from a SaveFileDialog. Next, you start doing whatever you need to be doing to the file, based on the filename.
Blog
HowTo: open all files from the Find Results window
Here’s a quick Visual Studio tip for you…
I frequently search for a specific text in my solution because I need to do something in all places where that text occurs. Today I found out how you can open all the files that are mentioned in the Find Results window.
Search for the text you’re looking for. In my case this is ITest*.
Open up the Search Results window and select all the records where the text was found.
Blog
HowTo: have Visual Studio open XAML documents in code view
Just a small post to start the new year… and let it be a good one!
When opening a XAML document in Visual Studio, it opens in split view by default. This might become annoying when you have a large XAML document, because all the content needs to be rendered before you can get some work done.
Here’s how you can have Visual Studio open XAML documents in code view:
Blog
Visual Studio: Zero-impact Projects & Cutting/copying empty lines
Yesterday I remembered two Visual Studio options Sara Ford told about in a presentation of her I attended a while back. Changing them made me happy… 🙂
Zero-impact projects When I have to test something real quick, I tend to create a new project in Visual Studio and scribble some code to test whatever I want to test at that point. This causes my project directory to be filled with projects named WindowsFormsApplication14 or something like that.
Blog
Running Windows Vista on a MacBook Pro
When installing Windows Vista on a MacBook Pro, the default driver for the Wireless Network Adapter doesn’t function properly. To get the Wireless Network Adapter to work, first install the Boot Camp Services by inserting your OS X DVD and running the setup. Next you need to install the Boot Camp 2.1 update. You can download that one by running Apple Software Update, which is installed as part of the Boot Camp Services.
Blog
HowTo: Add a body onload script to a page that uses a MasterPage
When you use a MasterPage to define the design of your website, you might come across the problem that there is no body element in a web content form. This can be a problem when you want to add an onload script to a specific page. You could of course add the onload on the MasterPage, but you might not want the script to run on every page. There are several workarounds to fix this ‘problem’.
Blog
The absolute minimum every software developer …
One of the posts that is being read quite frequently over here is HOWTO: Encode a password using MD5 in C# (or: howto calculate the MD5 hash for a string). One of the (many) reactions to that post was from one Simucal, stating:
Also, to the original poster, Rick van den Bosch… shame on you for using ASCIIEncoding.Default.GetBytes(). You do realize that would seriously restrict the usefulness of your method to working only in languages that ASCII has the character sets for, right?
Blog
Backing up and restoring Visual Studio settings
When roaming the MSDN forumsfor unanswered questions for me to answer, I come across a lot of questions about any of the following:
Intellisense acting weird Intellisense not showing up at all Menu items that are all garbled up Missing buttons on toolbars Complete toolbars missing Keyboard shortcuts acting weird Keyboard shortcuts not working at all … In most cases, resetting the Visual Studio settings to the default settings using devenv /resetsettingssolves any problems that are in that list.
Blog
LinkButton inside UpdatePanel results in full postback, UpdatePanel not triggered
When you dynamically generate a LinkButton in code that will be placed inside an UpdatePanel, you’ll experience that the Click event for the LinkButton results in a full postback in stead of the UpdatePanel being triggered. There’s a rather simpel solution to this problem…
First, let’s take a look at the scenario. Consider this HTML:
There’s a literal control outside of the UpdatePanel. There’s a second literal control inside the UpdatePanel.
Blog
Getting the ModalPopupExtender to work in SharePoint 2007
Getting the ModalPopupExtender from the Ajax Control Toolkit to work (decently) in SharePoint was not exactly a walk in the park. With a default SharePoint installation, the modal popup is partly positioned ‘outside’ of the page (you only see the bottom right part of the popup in the top left corner of the browser). Postbacks are not executed or executed poorly and the page gets garbled up. A possible solution for the positioning of the popup is to set the X and Y property of the ModalPopupExtender.
Blog
I8 converter – Download (sourcecode available)
One of my colleagues pointed out the new Fine-grained password policy feature in Windows Server 2008. As you can see in this postat The Sean Blog, some values have to be entered in the I8 format, which isn’t very user friendly. Because of that, he asked me if I could whip up a tool that converts days, hours, minutes and seconds to the I8 format. I quickly put together this small tool for him.
Blog
PageRequestManagerServerErrorException (status code 500)
In a quick AJAX demo I had to create today, I ran into a (somewhat cryptic) PageRequestManagerServerErrorException. I needed a simple form of the Cascading Dropdown{.}, one that doesn’t use a (web)service for its data, but gets it from a simple method. Here’s the setup, and the cause…
Lets start with the exact error message:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server.
Blog
Hooray (x 2) for MSDN library Community content
There are several steps to creating a custom web service to be hosted in SharePoint. The MSDN library{.} has a walkthrough on creating a custom web service{.}. After having followed this walkthrough thoroughly, I though my web service was good to go. Unfortunately all I saw was an error: “Could not load type ‘ThisAndThat’ from assembly ‘SoAndSo’”. Just as I was about to search for an answer somewhere online, I remembered that the MSDN library features the Community content for little over a year now{.
Blog
HowTo: Set the Theme for a MasterPage (from code)
The MasterPage doesn’t have a property for setting the Theme at design time. Despite this, I wanted to set the Theme for a MasterPage, so I decided to set it from code. I was aware of the possibility to set the Theme through the web.config, but that wasn’t the way I wanted to set it. One of the reasons being it would result in the theme being applied to the entire website.
Blog
HowTo: Disable specific Code Analysis rules for a Team Build
Thanks to the MSDN forums{.} (and specifically one Hua Chen), I found a way{.} to disable specific code analysis rules for a team build. In this post I’ll combine the steps I followed earlier with the description given at the MSDN forum. I’ll start out with some steps earlier on in the process: how to quickly get a list of all the code analysis rules you want to disable (without having to type it all yourself 😉 ).
Blog
Disable specific Code Analysis rules for a Team Build
After searching a bit, I found a way to disable specific Code Analysis rules for a team build. Or at least I thought so… The RunCodeAnalysis tag in my build.proj file is set to ‘Always’ to override the individual project settings, and I added the ‘CodeAnalysisRules’ tag to exclude some rules as a test. (See below for a part of the build.proj file.) I ran a few builds, but the tag doesn’t seem to do what is supposed to.
Blog
Unit Test Adapter threw an exception
“Unit Test Adapter threw exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information..”
This error popped up at one of the testers of our project this morning. The unittests he selected worked fine on my machine, but all failed on his with the above message. After searching a bit we found that the only thing which was different between my testrunconfig and his was that he enabled code coverage for the assembly these unittests were pounding away at.
Blog
Defensive programming
We all encountered them in the field somewhere along the way: pieces of code that are based on assumptions. There’s something fundamentally wrong in assuming when writing code. I can understand that, looking at the big picture, you sometimes have to make an assumption when developing software. Some things you just can’t know for sure. This might concern something simple like the resolution of the targeted audience. But most of the time these kinds of assumptions are based on experience or plain old common sense.
Blog
HowTo: determine which object (and method) called another method
Sometimes when you’re inside a method you would like to know which method called it. Or even which object. For instance when you write a TraceListener, it might be pretty cool to make the TraceListener smart enough to find out what object called him and from which method. The StackTrace object in .NET makes this pretty easy. Here’s a howto…
First, we iterate through the stackframes that are available on the stack, looking for the one we need.
Blog
HowTo: read your configfile when using no-touch deployment
Earlier I posted about reading a configfile when using no-touch deployment. Several people have contacted me to post the code, so here it is.
Blog
Howto: create a custom httpHandler
If you would like to (for example) make sure all the jpegs on your site are displayed including a copyright text or something like that, you could use the example I posted before. But it would be easier to write a custom httpHandler. Here’s a small howto:
Add a class to a WebApplication, and give it a decent name. Mine is customHandler.
Have the class implement the IHttpHandler interface (found in the System.
Blog
HowTo: implement a list that sorts based on value ( not key ! )
<div> <font face="Courier New"> <font color="#0000ff">private string</font> theKey;</font> </div> <div> <font face="Courier New"> <font color="#0000ff">private string</font> theValue;</font> </div> <div> <font face="Courier New"> </font> </div> <div> <font face="Courier New"> <font color="#0000ff">public string</font> Key</font> </div> <div> <font face="Courier New"> {</font> </div> <div> <font face="Courier New"> <font color="#0000ff">get</font></font> </div> <div> <font face="Courier New"> {</font> </div> <div> <font face="Courier New"> <font color="#0000ff">return</font> theKey;</font> </div> <div> <font face="Courier New"> }</font> </div> <div> <font face="Courier New"> }</font> </div> <div> <font face="Courier New"> </font> </div> <div> <font face="Courier New"> <font color="#0000ff">public string</font> Value</font> </div> <div> <font face="Courier New"> {</font> </div> <div> <font face="Courier New"> <font color="#0000ff">get</font></font> </div> <div> <font face="Courier New"> {</font> </div> <div> <font face="Courier New"> <font color="#0000ff">return</font> theValue;</font> </div> <div> <font face="Courier New"> }</font> </div> <div> <font face="Courier New"> }</font> </div> <div> <font face="Courier New"> </font> </div> <div> <font face="Courier New"> <font color="#0000ff">public</font> KeyValuePair(<font color="#0000ff">string</font> key, <font color="#0000ff">string</font> value)</font> </div> <div> <font face="Courier New"> {</font> </div> <div> <font face="Courier New"> theKey = key;</font> </div> <div> <font face="Courier New"> theValue = value;</font> </div> <div> <font face="Courier New"> }</font> </div> <div> <font face="Courier New"> </font> </div> <div> <font face="Courier New"> <font color="#0000ff">public int</font> CompareTo(<font color="#0000ff">object</font> obj)</font> </div> <div> <font face="Courier New"> {</font> </div> <div> <font face="Courier New"> <font color="#0000ff">if</font> (obj == <font color="#0000ff">null</font>)</font> </div> <div> <font face="Courier New"> {</font> </div> <div> <font face="Courier New"> <font color="#0000ff">return</font> 1;</font> </div> <div> <font face="Courier New"> }</font> </div> <div> <font face="Courier New"> <font color="#0000ff">else</font></font> </div> <div> <font face="Courier New"> {</font> </div> <div> <font face="Courier New"> KeyValuePair check = (KeyValuePair)obj;</font> </div> <div> <font face="Courier New"> <font color="#0000ff">return</font> Value.
Blog
HowTo: Thread safe singleton implementation of a class
Normally, if you would like a singleton implementation of a class, you would go about it a little bit like this:
<p> </font></font></font>The trouble here is that this implementation is not thread safe. The reason I post this is I recently ran into some code of an old colleague of mine (from my former employee) and some tests showed his singleton class was instantiated several times when the application was stressed with requests from the start, which caused unwanted lag in the application.
Blog
Howto: present a Crystal Reports report as a PDF in an ASP.NET web application (without using temporary files)
This one is actually quite simple: Crystal Reports supports exporting to a PDF. Exporting can be done to disk, or to a stream. And a stream can be written to the Repsonse property of a page. And there you go 😉
// Variable declarationCrystalTest crystalTest;MemoryStream memoryStream;// Create a new instance of the report you want to display as a PDFcrystalTest = newCrystalTest();// TODO: Add some stuff here to fill the report with data// Export the report to a stream with the PDF formatmemoryStream = (MemoryStream)crystalTest.
Blog
HOWTO: display your assembly @ Add Reference
You might want to be able to let your assembly show up in the Add Reference window in Visual Studio without the user having to browse for it. When you install your assembly in the GAC, it doesn’t automatically show up in the Add Reference window, because it doesn’t enumerate all assemblies in the GAC. Installing in the GAC only eliminates the need to copy assemblies localy when referencing them. Microsoft doesn’t recommend putting assemblies in the GAC by the way…
Blog
HOWTO: Encode a password using MD5 in C# (or: howto calculate the MD5 hash for a string)
The following method returns the MD5 hash for any given string. For instance for a password. It might be of some assistance when you’re trying to validate user credentials but you don’t want to store the password readable in the database.
For this method, you’ll need the following using statements:
using System; using System.Text; using System.Security.Cryptography; [...] public string EncodePassword(string originalPassword) { //Declarations Byte[] originalBytes; Byte[] encodedBytes; MD5 md5; //Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password) md5 = new MD5CryptoServiceProvider(); originalBytes = ASCIIEncoding.
Blog
HOWTO: Draw your own string (URL, copyright) on each displayed picture in an ASP.NET website
The AdRotator .NET provides can be used to show a different image each time a page is visited. You could write a webpage which does this for you, but it’s probably not very useful. Although you need to change the XML file when changing the images to be showed when you use an AdRotator, but that’s not the issue here.
Something .NET doesn’t deliver is a control to add your own text to an image when it is displayed on a webpage.
Blog
HOWTO: create an animated GIF using .NET (C#)
.NET does not give you possibilities to create animated GIFs through GDI+. At least 1.1 doesn’t, they might incorporate it in 2.0. But there are ways to make them! This solution is one I used myself, and I’m very pleased!
//Variable declaration StringCollection stringCollection; MemoryStream memoryStream; BinaryWriter binaryWriter; Image image; Byte[] buf1; Byte[] buf2; Byte[] buf3; //Variable declaration stringCollection = a_StringCollection_containing_images; Response.ContentType = “Image/gif”; memoryStream = new MemoryStream(); buf2 = new Byte[19]; buf3 = new Byte[8]; buf2[0] = 33; //extension introducer buf2[1] = 255; //application extension buf2[2] = 11; //size of block buf2[3] = 78; //N buf2[4] = 69; //E buf2[5] = 84; //T buf2[6] = 83; //S buf2[7] = 67; //C buf2[8] = 65; //A buf2[9] = 80; //P buf2[10] = 69; //E buf2[11] = 50; //2 buf2[12] = 46; //.