IIS Express – Disabling anonymous authentication

StackOverflow: IIS Express is automatically disabling anonymous authentication for my project, why?

To disable anonymous authentication, I found updating the following element in the project file (i.e. csproj, vbproj) allowed me to debug my application with anonymous access.

<IISExpressAnonymousAuthentication>disabled</IISExpressAnonymousAuthentication>

Changing the IISExpressAnonymousAuthentication setting to enabled fixes the issue (it can also be done within Visual Studio, select project, F4, set Anonymous Authentication in the properties grid to Enabled).

Enable CORS IIS Express

While debugging a .NET MVC WebAPI project, I was getting the error, related to cross origin resource sharing:

No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:XXXXX’ is therefore not allowed access.

Once I added the following custom header to the IIS Express application host configuration, the errors disappeared.

<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />

I had to update the C:\Users\username\Documents\IISExpress\config\applicationhost.config file, by using Notepad++ (don’t forget to “Run as administrator”). You can also use AppCmd.exe, if command-line is your thing.

I also read updating the C:\Program Files (x86)\IIS Express\AppServer\applicationhost.config file can fix the problem, but this didn’t work for me.

Final result:

<httpProtocol>
 <customHeaders>
  <clear />
   <add name="X-Powered-By" value="ASP.NET" />
   <add name="Access-Control-Allow-Origin" value="*" />
   <add name="Access-Control-Allow-Headers" value="Content-Type" />

 </customHeaders>

</httpProtocol>

https://code.msdn.microsoft.com/CORS-support-in-ASPNET-Web-01e9980a/sourcecode?fileId=60420&pathId=1058340413

Kendo UI Editor – A FreeTextBox Replacement

The Kendo UI Editor is simple to use and easy to implement. I found it to be a great FreeTextBox replacement, the editor that I’ve used in the past.

Here are a few reasons:

  • Kendo editor is configured client-side in the JavaScript
  • Kendo editor doesn’t rely on a server side control on the page, allows more control of what’s rendered
  • No need to recompile when a configuration change is made to the Kendo editor

Kendo UI Editor (JSFiddle)

Cache JQuery Selectors To Improve Performance

JQuery logo text

An easy way to improve jQuery performance is to cache reused jQuery selectors. This prevents jQuery from having to search the entire DOM for each instance the selector is being used.

For example, instead of this:

$(document).ready(function() {
	$('#FName').html('My First Name');
	$("#changeName").click(function() {
		$('#FName').html('My Other First Name');
	});
});

Try this:

$(document).ready(function() {
	var fName = $('#FName');
	fName.html('My First Name');
	$("#changeName").click(function() {
		fName.html('My Other First Name');
	});
});

By the way, jQuery id selector maps to the native JavaScript function document.getElementById().

Short Experiment

I still prefer document.getElementById() over jQuery ID selector, when possible, see the results below:

Cache JQuery Selectors (JSFiddle)

String.Format to set a constant in .NET

Today I began working on the base framework for a new project. In the past we would just copy an existing project and remove what we don’t need, so I thought this would be a good time to make the framework more generic to speed up this part of the process for future projects. This also would prevent having to copy and replace for constants, variables, functions, class names, etc. based on the name of the project as we’ve done in the past. I say all of this to point out something I found that was new to me.

There were constants in the framework that needed to be changed, for example:

Private Const cUserName As String = "ProjectUserName"

Where “Project” in “ProjectUserName” would need to be changed based on the name of the project, this happen for several other constants. So I tried setting the constant like this:

Private Const cName As String = String.Format("{0}UserName", AppSetting.ProjectID)

And got “Constant expression is required.” which wasn’t clear to me. After some research I found that a constant has to be set by a compile time constant and the result of String.Format isn’t a compile time constant.

I finally just changed the constant to a shared readonly variable.

Private Shared ReadOnly cUserStoreName As String = String.Format("{0}UserName", AppSetting.ProjectID)

Values considered false in JavaScript – false, null, undefined, NaN

Unofficial JavaScript logo
The false values in JavaScript:

  • false
  • null
  • undefined
  • The empty string ”
  • The number 0
  • The number NaN (result of an operation that cannot produce a normal result)

False JavaScript Values (JSFiddle)

All other values evaluate to true, including true, the string ‘false’, and all objects.

Another tidbit about NaN is that it is not equal to any value, including itself.

FreeTextBox – Set default font and size

When using the FreeTextBox HTML editor, the default font styles have to be set in the stylesheet specified in the DesignModeCss property.

FreeTextBox - Set default font and size

In my case I created a stylesheet and saved it as /App_Themes/Default/FreeTextBox.css, with the following:

body
{
font-family:Georgia;
font-size:14pt;
}

Then I set the DesignModeCss property:

<uc:FreeTextBox ID="ucFreeTextBox" DesignModeCss = "~/App_Themes/Default/FreeTextBox.css" Runat="server" />

And that’s it.

SQL Server Reporting Services (SSRS) – Download Multiple RDL files

ssrs dashboardI needed to migrate multiple SSRS reports (.rdl’s) between environments (production -> qa ->development) and didn’t want to download/upload each individual report. I searched but couldn’t find a solution built into SSRS report manager, so I began my Google search. I found a solution on Code Project (SSRS Downloading .RDL Files) that worked after some tweaking.

This project written in C# using Visual Studio 2010, and all I really needed to change was the URL to the SSRS web service to get the project up and running. Some of the other changes I made included building the folder structure as it is on the SSRS server and only saving the .rdl files.

Here’s what I came up so far:
SSRSExtractor.zip

After I ran the project and downloaded all the reports really fast, I still had to manually upload the ones I needed to migrate. When I have time hopefully I can implement uploading to an SSRS server into the project.

SQL Server – CHAR – Converts an int ASCII code to a character.

CHAR can be used to insert control characters into character strings. The frequently used control characters are:

  • CHAR(9) = Tab
  • CHAR(10) = Line Feed
  • CHAR(13) = Carriage Return

My problem was trying to export data in Management Studio from a 3rd party application database into a spreadsheet.

I found knowing this useful when a column contained carriage returns as delimiters (which looked like spaces in Management Studio) so my SQL statement turned out to be something like this:

--; can be change to whatever is useful
SELECT
REPLACE(column_with_carriage_return_delimiters, CHAR(13), ';')
FROM MyDBTable

Now I could copy/paste the result in a text editor and replace ; with whatever I needed. There maybe a better solution but this is what I came up with so far.