Wednesday, January 31, 2018

Visual Studio Continually Prompts to Sign Into Microsoft Account

Is Visual Studio continually prompting you to sign into your Microsoft account (sometimes failing), even though the information is correct?

You can find the logs in %USERPROFILE%\AppData\Local\Temp\servicehub\logs to see more information.

Inside those logs, there can be various messages, but many should be similar to "Problem Acquiring a token".

 Example


01/31/2018 09:20:22 : Error : Problem Acquiring a token silenly for resource: 'https://graph.windows.net/', tenant:'00000-00000-00000-00000', User: '1_asdlkB40309asldqsd1234asdfas21a1234' due to 'Microsoft.IdentityService.Clients.ActiveDirectory.AdalException: multiple_matching_tokens_detected: The cache contains multiple tokens satisfying the requirements. Call AcquireToken again providing more arguments (e.g. UserId) at Microsoft.IdentityService.Clients.ActiveDirectory.TokenCache.LoadSingleItemFromCache(CacheQueryData cacheQueryData, CallState callState) at Microsoft.IdentityService.Clients.ActiveDirectory.TokenCache.LoadFromCache(CacheQueryData cacheQueryData, CallState callState) at Microsoft.IdentityService.Clients.ActiveDirectory.AcquireTokenHandlerBase.d__55.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityService.Clients.ActiveDirectory.AuthenticationContext.d__57.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityService.Clients.ActiveDirectory.AuthenticationContext.d__41.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Developer.IdentityService.AccountProvider.NetworkServicesImpl.d__8.MoveNext() ErrorCode: multiple_matching_tokens_detected'

After searching and trying a ton of solutions, I found the one that should work for every issue related to acquiring tokens in Visual Studio.

The Solution


Close all instances of Visual Studio and delete the folder %LOCALAPPDATA%\.IdentityService 

The next time you open Visual Studio your sign-in with your Microsoft Account should be successful. 

Original Source: https://developercommunity.visualstudio.com/content/problem/17315/cant-add-new-account-with-vsts-online-failed-to-re.html

Monday, November 30, 2015

Html.AntiForgeryToken() automatically adds HTTP response header X-Frame-Options

Just a note that using @Html.AntiForgeryToken() in MVC will automatically send the X-Frame-Options: SAMEORIGIN http response header.

Tuesday, May 5, 2015

Add Pingdom Probe Server IPs to IIS using PowerShell

I'm by no means a PowerShell script person.  It's pretty useful though, so after an hour or so along with a bunch of internet searches, I came up with a script to add the list of Pingdom Probe servers to my IIS allow list.

This script will parse the list of Pingdom probe servers (https://support.pingdom.com/Knowledgebase/Article/View/61/0/probe-servers) and add the given IPs to the IP Restriction Allow list for an IIS application.


$applicationPath = "Default Web Site/ApplicationName"

$doc = [xml](Invoke-WebRequest -URI "https://www.pingdom.com/rss/probe_servers.xml")
$ns = New-Object Xml.XmlNamespaceManager $doc.NameTable
$ns.AddNamespace("pingdom", "http://www.pingdom.com/ns/PingdomRSSNamespace")
$nodes = $doc.SelectNodes("/rss/channel/item/pingdom:ip", $ns)

$currentIPList = Get-WebConfiguration system.webServer/security/ipSecurity -Location $applicationPath -PSPath IIS:\

foreach($ip in $nodes)
{
    $exists = $currentIPList.Collection | where { $_.ipAddress -eq $ip.'#text' }

    if (!$exists)
    {
        $configEntry = @{allowed="true"; ipAddress=$ip.'#text'}
        Add-WebConfiguration  system.webServer/security/ipSecurity -Location $applicationPath -Value $configEntry -PSPath IIS:\
        "Added: " + $ip.'#text'
    }
}

Tuesday, January 13, 2015

Disable Windows 8 Auto Repair

Windows 8 comes with a handy "feature" called "Automatic Repair", which is supposed to fix your Windows installation.

I've seen this utility ran dozens of times, on dozens of machines, without success.  Not a single time has it worked.  I'll take my chances with Windows not booting and be fixable, so goodbye auto repair.

To disable it, open up cmd.exe as Administrator and run:

bcdedit /set {current} recoveryenabled No
Source: https://social.technet.microsoft.com/Forums/windows/en-US/df2eed2a-67e2-498e-ae6b-42d171ccacd3/disablebypass-windows-8-automatic-repair?forum=w8itprogeneral

Friday, September 12, 2014

Making jQuery and Boostrap 3 and "hide" class work together

One of the problems with using jQuery's show and hide methods is that they are not compatible with the provided Bootstrap css classes "show" and "hide".

What is the problem? Bootstrap's css class looks like this:



.hide {
  displaynone !important;
}

Those important styles are necessary on some elements to make the behavior as expected. However, jQuery doesn't overwrite them when setting css attributes with the built-in show/hide methods. The recommended way that I found is to manually use .addClass("hide") and .removeClass("hide")...which is way too annoying.



Add the following JavaScript code after the initial jQuery .js file load and all is well.

var originaljQueryShow = jQuery.fn.show;
var originaljQueryHide = jQuery.fn.hide;
jQuery.fn.extend({
    show: function () {
        var result = originaljQueryShow.apply(this, arguments);
        jQuery(this).removeClass("hide");
        return result;
    },
    hide: function () {
        var result = originaljQueryHide.apply(this, arguments);
        jQuery(this).addClass("hide");
        return result;
    }
});


This lets the original functionality of the jQuery show() and hide() to be maintained, while adding transparent support for the Bootstrap css hide class.

Sunday, January 19, 2014

Entity Framework 6 + Stored Procedure = The type or namespace name 'Objects' does not exist in the namespace 'System.Data'

(this post is formatted poorly, it will be fixed later because I really need to post this one before I forget it)

On my latest project I upgraded to Entity Framework Version 6 and everything was fine until I tried to add a Stored Procedure function import.

After adding that I could no longer build the project and the error message of "The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)" started showing up.

I found the solution here and the fix is to download the Entity Framework 6 Tools for Visual Studio 2012/2013.

Note:  After you install the tools, your model will still not compile.  To fix it you must either:

  • Delete and re-add the Model.edmx to your project
OR
  • Create another model and copy the Context.tt file from it over your initial model.  After you copy the .tt, on Line 5 you'll need to set the name of your original Model.edmx
Line 5: const string inputFile = @"OriginalModel.edmx";
Now, after it compiled I ran into the fun error message "System.InvalidOperationException: The value of EntityCommand.CommandText is not valid for a StoredProcedure command. The EntityCommand.CommandText value must be of the form 'ContainerName.FunctionImportName'."  At this point I was almost ready to write EF6 off as unusable, but I found a page at http://www.dotnetbits.com/entity-framework-6-t4-templates/ that gave me the updates to Context.tt that I needed.

Look for the method signature

public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)

Replace that method with

public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
{
var parameters = _typeMapper.GetParameters(edmFunction);
var returnType = _typeMapper.GetReturnType(edmFunction);
var callParams = _code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()));
if (includeMergeOption)
{
callParams = ", mergeOption" + callParams;
}
return string.Format(
CultureInfo.InvariantCulture,
"return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\"{2});",
returnType == null ? "" : "<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">",
edmFunction.FullName,
callParams);
}

Monday, September 30, 2013

Create an ad-hoc network in Windows 8

My USB drive died and I needed a very quick way to get some larger files from my tablet to my laptop.  The largest problem was that I was connected over an open WiFi network in my hotel room and I needed it to be as secure as I could make it.

So, creating an ad-hoc network came to mind between my laptop and tablet to transfer the files.  I have never actually had a need to create one of these, but the steps are more manual than I remember them being in previous versions of Windows.

I found my answer at http://www.addictivetips.com/windows-tips/how-to-create-wireless-ad-hoc-internet-connection-in-windows-8/  The site has detailed steps and pictures if you need them, so I'll give a very quick run-down of what needs done.

Notes:

  • Your NIC needs to support virtualization (see the website for more info).  Any modern NIC should support it, however.
  • Your ad-hoc network will broadcast a public SSID.
  • The encryption is WPA-2 Personal.
  • Copying between the tablet and the laptop is pretty slow, but it works over a network share that I made.
To enable it:
  1. From a command prompt run:
    1. netsh wlan set hostednetwork mode=allow ssid=NETWORK_SSID key=PASS_KEY
    2. netsh wlan start hostednetwork
  2. Open up the network adapter list, you can search for "View Network Connections" in the Windows 8 search.
  3. Enable Internet Connection Sharing (ICS) by going to the Network Adapter properties you want to share (the same place you'd assign an IPv4 static IP at) and choose the Sharing tab.  Then just enable it to be shared by others.
  4. Look for your SSID on your other device(s) and connect to it.