Tuesday, May 16, 2017

Cannot import the following key file. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate

I got an error when compiling a project in TeamCity. This particular project had assemblies signed. TeamCity threw an error that said:

Cannot import the following key file. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_FFA0xxxxx

The fix to this problem is quite simple:

1) Open the Developer Command Prompt for VS 2017
2) Type:

     sn -i "c:\path to your pfx\file.pfx" VS_KEY_xxxxxx

where the VS_KEY is what Team City said

Sunday, April 9, 2017

ASP.NET Identity - Invalid token error

I was generating a code for a user to reset her password. However, this error came up when trying to reset the password. I had 2 problems:

1) The token was being generated in a computer that was not where the token was actually used. I read in SO that the token is tied to a key in the web.config, so either the web.config -keep in mind that ASP.NET has a hierarchy of web.config files, so there's more than 1- needs to match or you need to generate and use the token in the same server.
2) The token contained the plus sign (+). When using it, the server encoded it as a space, so you need to do string.Replace(" ", "+")

Sunday, January 22, 2017

Web deploy error when publishing to azure: String larger than expected

This happened to me while trying to deploy 1 files (a dll) to azure. I couldn't find any answers on SO or other sites. The solution was to deploy all files as opposed to deploying only 1 file

Sunday, December 11, 2016

Azure returning a 404 for woff files

This is actually a configuration error, as described here


The solution was to add the following to the web.config:

      <mimeMap fileExtension="woff" mimeType="application/font-woff" />
      <mimeMap fileExtension="woff2" mimeType="application/font-woff" /> 


Thursday, September 15, 2016

OpenVPN not changing my IP address

When I installed the OpenVPN client and connected to a VPN it changed my IP address correctly. However, subsequent times it didn't change it. It turned out I had to run the application as an administrator, and that was it.

Monday, June 27, 2016

How to return a 401 status code using ASP.NET MVC 5 and OWIN

This time I was trying to force users to the login page after an Ajax request failed because of an expired session. I was getting something like this in the response:

X-Responded-JSON: {"status":401,"headers":...
I investigated a little and turned out you have to add this code to your Startup.Auth.cs file:

Provider = new CookieAuthenticationProvider
  OnApplyRedirect = ctx =>
    if (!IsAjaxRequest(ctx.Request))

Also, in your filter I suggest you do something like this:

if (filterContext.HttpContext.Request.IsAjaxRequest())
filterContext.HttpContext.Items["RequestWasNotAuthorized"] = true;
filterContext.HttpContext.Response.StatusCode = 401;
filterContext.Result = new HttpUnauthorizedResult();

And then handle it in JavaScript like this:

$(document).ajaxError(function (xhr, props) {
if (props.status === 401) {

More information on the error can be found here:

Wednesday, June 15, 2016

A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - The handle is invalid.)

The solution is simple, just reset IIS. If that doesn't work, this SO question will help