Traditionally, closing browsers automatically deletes "session" cookies. (Cookies that are defined to represent a login session that should be automatically disconnected when a browser closes.)
In 2012, Chrome changed its behavior so that closing the browser does not delete session cookies. (This newer behavior is active if you enable the common Chrome setting: On startup: Continue where you left off.) This new behavior allows reopening the browser (perhaps hours later, by another person) and having your last active pages, along with any associated login sessions, automatically reloaded. (To be fair, many sites will timeout your session if it seems inactive after a short period of time. But many, e.g., GMail, won't.)
This is a bad thing if you use Chrome on a public access computer (e.g., library). You should now explicitly logout of all sites before closing Chrome. Which means you should be careful not to accidentally navigate away from a logged in site and subsequently forget to navigate back and explicitly logoff.
The pros & cons of this new behavior are discussed in the Chrome bug tracker Issue 128513. It seems primarily useful when Chrome restarts to apply software updates (without forcing you to logoff all your websites). Firefox has similar behavior which is also debated. As pointed out there, this browser behavior is at odds with the documented behavior of session cookies.
There is a Chrome setting to force delete all cookies when the browser is closed. (The "Keep local data only until you quit your browser" option described here.) Unfortunately, this is overkill in most situations.
Bottom line: Be aware.
Friday, February 17, 2017
Monday, August 11, 2014
SQL Server Reporting Services (SSRS) – “HTTP 401.1 – Unauthorized Logon Failed”
Symptom:
When
you browse to the ReportServer and Reports virtual roots using the host name specified
in your SSL certificate you are prompted three times to log in then land on a
blank page. Or you receive an ‘HTTP 401.1 – Unauthorized: Logon failed’
message.
Note You
only receive this error message if you try to browse directly on the server. If
you browse from another computer in the network, the SSRS site works as
expected.
Cause:
This issue occurs because
of a loopback-check security feature added in Windows Server 2003 SP1. Authentication
now fails if the host fully-qualified domain name (FQDN) specified in either your SSL certificate or any
custom host header (CNAME) alias that you use, does not match the local
computer name.
Work Around:
This issue and workaround
is more fully explained in Microsoft articles:
You should refer to and follow the
instructions there.
If those articles are
no longer available, a (possibly now out-of-date) snapshot of the instructions is
reproduced below.
Important This section, method, or task contains
steps that tell you how to modify the registry. However, serious problems might
occur if you modify the registry incorrectly. Therefore, make sure that you
follow these steps carefully. For added protection, back up the registry before
you modify it. Then, you can restore the registry if a problem occurs. For more
information about how to back up and restore the registry, click the following
article number to view the article in the Microsoft Knowledge Base:
322756
How to back up and restore the registry in Windows
Warning This workaround may make your computer or your network more vulnerable to attack by malicious users or by malicious software such as viruses. We do not recommend this workaround but are providing this information so that you can implement this workaround at your own discretion. Use this workaround at your own risk.
Create the Local Security Authority host names that can be referenced in an
NTLM authentication request
- Click Start, click Run, type regedit, and then click OK.
- Locate and
then click the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
- Right-click
MSV1_0, point to New, and then click Multi-String Value.
- In the Name column, type BackConnectionHostNames, and then press ENTER.
- Right-click
BackConnectionHostNames,
and then click Modify.
- In the Value data box, type the
CNAME or the DNS alias that is used for the local shares on the computer,
and then click OK.
Note Type each FQDN host name on a separate line.
Note If the BackConnectionHostNames registry entry exists as a REG_DWORD type, you have to first delete the BackConnectionHostNames registry entry. - Exit
Registry Editor, and then restart the computer.
Wednesday, January 8, 2014
Why ReSharper keyboard shortcuts fail over Remote Desktop Connection
I use the ReSharper plugin for Visual Studio.
I discovered that the reason some of the newer ReSharper keyboard shortcuts only work “sometimes” for me is that they are usurped by Microsoft Remote Desktop Connection (RDC).
E.g., ReSharper’s old Ctl-W is now Ctl-Alt-Left Arrow / Right Arrow. However those keys are used by RDC (and can’t be changed).
List of RDC Keyboard Shortcuts:
http://windows.microsoft.com/en-us/windows-vista/what-shortcut-keys-can-i-use-in-remote-desktop-connection
A hack workaround:
http://superuser.com/questions/327866/remote-desktop-sending-ctrl-alt-left-arrow-ctrl-alt-right-arrow-to-the-remote-p
I discovered that the reason some of the newer ReSharper keyboard shortcuts only work “sometimes” for me is that they are usurped by Microsoft Remote Desktop Connection (RDC).
E.g., ReSharper’s old Ctl-W is now Ctl-Alt-Left Arrow / Right Arrow. However those keys are used by RDC (and can’t be changed).
List of RDC Keyboard Shortcuts:
http://windows.microsoft.com/en-us/windows-vista/what-shortcut-keys-can-i-use-in-remote-desktop-connection
A hack workaround:
http://superuser.com/questions/327866/remote-desktop-sending-ctrl-alt-left-arrow-ctrl-alt-right-arrow-to-the-remote-p
Wednesday, December 18, 2013
How to make elevated Windows programs recognize network drives
In Windows Vista or newer, if User Access Control (UAC) is enabled, network drives mapped while in a non-elevated state are not accessible to the same user in an elevated (administrator) state.
More detail in Microsoft articles here and here.
For example, after mapping a network drive, P:, from Windows Explorer (not elevated), I launch an elevated command prompt ("Run as administrator") and run the net use command. It shows the drive mapping exists, but rather than Status being OK, it is Unavailable.
Workarounds:
More detail in Microsoft articles here and here.
For example, after mapping a network drive, P:, from Windows Explorer (not elevated), I launch an elevated command prompt ("Run as administrator") and run the net use command. It shows the drive mapping exists, but rather than Status being OK, it is Unavailable.
Workarounds:
- Map the drive twice: non-elevated and elevated. (E.g., launch an elevated command window and use the net use command.)
- Set a registry setting that will force Windows to make the network drives available to both the standard and administrator accounts automatically:
Create a new DWORD entry with the name HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System/EnableLinkedConnections and value 1.
See articles here and here.
Warning: This can cause problems; see this Microsoft hotfix. - Disable UAC.
Tuesday, August 14, 2012
How to tell which SQL Server version, service pack, edition, etc. is running
Execute the following query:
SELECT SERVERPROPERTY('productversion') as 'Product Version', SERVERPROPERTY('productlevel') as 'Patch Level', SERVERPROPERTY('edition') as 'Product Edition', SERVERPROPERTY('buildclrversion') as 'CLR Version', SERVERPROPERTY('collation') as 'Default Collation', SERVERPROPERTY('instancename') as 'Instance', SERVERPROPERTY('lcid') as 'LCID', SERVERPROPERTY('servername') as 'Server Name'
This useful info came from this blog post.
Friday, August 10, 2012
Perform an action on (e.g., "drop") all tables in a SQL Server database
Supposed you want to perform an action on all tables in a SQL Server database. (E.g., delete or truncate every table.)
You could generate a list of all the tables in the database by (first connecting to the database you want then) executing:
You could generate a list of all the tables in the database by (first connecting to the database you want then) executing:
Or you could use the hidden Microsoft stored procedure, sp_MSforeachtable.SELECT * FROM sys.Tables Order by name ASC
EXEC sp_MSforeachtable @command1 = "PRINT '?'"Or more destructively:
--print the tables names with owner(dbo)
EXEC sp_MSforeachtable @command1 = "SELECT * FROM ?"
-- Selects all the rows form all the table
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"This was gleaned from this blog post.
EXEC sp_MSforeachtable @command1 = "DELETE FROM ?"EXEC sp_MSforeachtable @command1 = "TRUNCATE TABLE ?"
Friday, July 27, 2012
File Types tab missing -- NirSoft to the rescue
Windows 7 and (worse) Windows Server 2008 no longer provide a GUI to fully edit file type associations.
Earlier Windows versions (e.g., XP) allowed you to edit this via the Windows file system explorer menu Tools > Folder Options... dialog, the File Types tab. There you could define which program is associated with each file extension:
The "File Types" tab is missing in Windows 7 and Windows Server 2008.
To the rescue is NirSoft with their FileTypesMan utility.
Earlier Windows versions (e.g., XP) allowed you to edit this via the Windows file system explorer menu Tools > Folder Options... dialog, the File Types tab. There you could define which program is associated with each file extension:
If you pushed "Advanced", you could then view the various file operations that could be performed:
And you could redefine how the programs were actually invoked to perform each action:
The "File Types" tab is missing in Windows 7 and Windows Server 2008.
To the rescue is NirSoft with their FileTypesMan utility.
Wednesday, June 27, 2012
Alway give extremely verbose error information
When programs encounter errors, they should always make available detailed information about what actually went wrong. If it's too verbose, or too technical for the expected audience, it should still be made available; either behind a "Details" button, or written in a log file.
An anti-example is the when the awesome tool, ReSharper, runs an NUnit test, it can first automatically build any changed projects. (Nice.) But when that build fails, it says "Build failed". That's it. No output in the build output or errors windows. No nothing.
(I found this nice blog post explaining what the problem was.)
A corollary of this philosophy is that when catching an exception and throwing a different exception, you should always nest/wrap/chain the caught exception as the inner exception of the new one. The outer exception might repeat information from the inner exception; include the inner exception anyway. The inner exception may be verbose, confusing, etc.; include it anyway.
(The only, rare "exception" to this rule is when the inner exception reveals sensitive information -- credentials, HIPPA info, etc. This is usually code running on a server, in which case the inner exception should instead be logged into a secure log file for possible later problem analysis.)
An anti-example is the when the awesome tool, ReSharper, runs an NUnit test, it can first automatically build any changed projects. (Nice.) But when that build fails, it says "Build failed". That's it. No output in the build output or errors windows. No nothing.
(I found this nice blog post explaining what the problem was.)
A corollary of this philosophy is that when catching an exception and throwing a different exception, you should always nest/wrap/chain the caught exception as the inner exception of the new one. The outer exception might repeat information from the inner exception; include the inner exception anyway. The inner exception may be verbose, confusing, etc.; include it anyway.
(The only, rare "exception" to this rule is when the inner exception reveals sensitive information -- credentials, HIPPA info, etc. This is usually code running on a server, in which case the inner exception should instead be logged into a secure log file for possible later problem analysis.)
Monday, June 11, 2012
Outlook does not include Deleted Items in Instant Search by default
Outlook's Instant Search doesn't include Deleted Items in the search results by default.
You can change this by enabling the corresponding checkbox in the Search Options dialog.
See this article, the section titled "INCLUDE THE DELETED ITEMS IN INSTANT SEARCH".
In Outlook 2010, the dialog looks like this:
You can change this by enabling the corresponding checkbox in the Search Options dialog.
See this article, the section titled "INCLUDE THE DELETED ITEMS IN INSTANT SEARCH".
In Outlook 2010, the dialog looks like this:
Wednesday, May 16, 2012
How .NET Exception stack traces are broken. How they can be fixed.
Unlike Java, .NET Exception stack traces are Less Than Worthy. There are many ways this is true. Today we will discuss how exception stack traces get lost when rethrown.
If you don't need to be convinced that this is a bug, not a feature, you can skip ahead to the workaround.
Imagine a program where Method1 calls Method2 calls Method3 calls Method4 which throws an exception. Imagine that one of these intermediate methods, Method2, needs to catch the exception, do some stuff (not shown), and then rethrow the caught exception.
public static void MyMain()
{
try { Method1(); } catch (Exception e) { Console.WriteLine(e); }
}
public static void Method1()
{
Method2();
}
public static void Method2()
{
try { Method3(); } catch (Exception e) { throw e; }
}
public static void Method3()
{
Method4();
}
public static void Method4()
{
throw new Exception("From Method4");
}
The ultimate caller, MyMain, prints the exception, including it's stack trace. Here's what it prints:
Wait, what happened to Method3 and Method4?
The problem is that, when C# throws an exception, it throws away (no pun intended) all stack trace information and starts over.
That is never what I want. (And if it was, I would more likely create a new exception object to throw for other reasons.)
There are ways around this:
As a typical example, suppose that you catch several different explicit exceptions using different catch blocks, but the body of the catch blocks are identical.
try {
AMethod();
} catch (ArgumentException e) {
DoSomething();
throw;
} catch (IOException e) {
DoSomething();
throw;
}
As a good programmer, you consider duplicated code to be evil, so you refactor it into a shared place. Perhaps a separate method; more often inline like this:
Exception ex = null;
try {
AMethod();
}
catch (ArgumentException e) { ex = e; }
catch (IOException e) { ex = e; }
if (ex != null) {
DoSomething();
throw ex;
}
But however you do it, you're no longer in a catch block when you rethrow. So you have to explicitly specify the exception on the throw. And you've lost your stack trace.
It turns out that Microsoft realized that they needed to preserve (remote) stack traces when rethrowing remote exceptions. So they built that functionality into the Exception class. Too bad they didn't realize the rest of us needed it too; so they made it private.
Here's a handy Exception extension method that will use reflection to invoke this private method.
public static class ExceptionHelper
{
public static void PreserveStackTrace(this Exception e)
{
_internalPreserveStackTrace(e);
}
private static readonly Action<Exception> _internalPreserveStackTrace =
(Action<Exception>)Delegate.CreateDelegate(
typeof(Action<Exception>),
typeof(Exception).GetMethod(
"InternalPreserveStackTrace",
BindingFlags.Instance | BindingFlags.NonPublic));
}
Here's Method2 (from the above example) rewritten to use this:
public static void Method2()
{
try { Method3(); }
catch (Exception e) { e.PreserveStackTrace(); throw e; }
}
And here is the stack trace now:
Note that Method2 appears twice in the trace: once where the exception was caught, and once where it was thrown. This is undesirable but better than losing the rest of the stack trace.
Caveats:
If you don't need to be convinced that this is a bug, not a feature, you can skip ahead to the workaround.
The Problem
Imagine a program where Method1 calls Method2 calls Method3 calls Method4 which throws an exception. Imagine that one of these intermediate methods, Method2, needs to catch the exception, do some stuff (not shown), and then rethrow the caught exception.
public static void MyMain()
{
try { Method1(); } catch (Exception e) { Console.WriteLine(e); }
}
public static void Method1()
{
Method2();
}
public static void Method2()
{
try { Method3(); } catch (Exception e) { throw e; }
}
public static void Method3()
{
Method4();
}
public static void Method4()
{
throw new Exception("From Method4");
}
The ultimate caller, MyMain, prints the exception, including it's stack trace. Here's what it prints:
System.Exception: From Method4at MiscCS4Tests.PreserveExceptionStackTrace2.Method1()
at MiscCS4Tests.PreserveExceptionStackTrace2.Method2()
at MiscCS4Tests.PreserveExceptionStackTrace2.MyMain()
Wait, what happened to Method3 and Method4?
The problem is that, when C# throws an exception, it throws away (no pun intended) all stack trace information and starts over.
That is never what I want. (And if it was, I would more likely create a new exception object to throw for other reasons.)
There are ways around this:
- Instead of throw e; use throw; That will preserve the stack trace. But this form of throw is only allowed inside a catch block.
- Create & throw a new exception object that nests the caught exception as the "inner exception". That will retain the full stack trace, if you chain through all the nested exceptions (which Exception.ToString does).
As a typical example, suppose that you catch several different explicit exceptions using different catch blocks, but the body of the catch blocks are identical.
try {
AMethod();
} catch (ArgumentException e) {
DoSomething();
throw;
} catch (IOException e) {
DoSomething();
throw;
}
As a good programmer, you consider duplicated code to be evil, so you refactor it into a shared place. Perhaps a separate method; more often inline like this:
try {
AMethod();
}
catch (ArgumentException e) { ex = e; }
catch (IOException e) { ex = e; }
if (ex != null) {
DoSomething();
throw ex;
}
But however you do it, you're no longer in a catch block when you rethrow. So you have to explicitly specify the exception on the throw. And you've lost your stack trace.
The Workaround
It turns out that Microsoft realized that they needed to preserve (remote) stack traces when rethrowing remote exceptions. So they built that functionality into the Exception class. Too bad they didn't realize the rest of us needed it too; so they made it private.
Here's a handy Exception extension method that will use reflection to invoke this private method.
public static class ExceptionHelper
{
public static void PreserveStackTrace(this Exception e)
{
_internalPreserveStackTrace(e);
}
private static readonly Action<Exception> _internalPreserveStackTrace =
(Action<Exception>)Delegate.CreateDelegate(
typeof(Action<Exception>),
typeof(Exception).GetMethod(
"InternalPreserveStackTrace",
BindingFlags.Instance | BindingFlags.NonPublic));
}
Here's Method2 (from the above example) rewritten to use this:
public static void Method2()
{
try { Method3(); }
catch (Exception e) { e.PreserveStackTrace(); throw e; }
}
And here is the stack trace now:
System.Exception: From Method4
at MiscCS4Tests.PreserveExceptionStackTrace2.Method4() in xxx.cs:line 170
at MiscCS4Tests.PreserveExceptionStackTrace2.Method3() in xxx.cs:line 165
at MiscCS4Tests.PreserveExceptionStackTrace2.Method2() in xxx.cs:line 159
at MiscCS4Tests.PreserveExceptionStackTrace2.Method2() in xxx.cs:line 161
at MiscCS4Tests.PreserveExceptionStackTrace2.Method1() in xxx..cs:line 154
at MiscCS4Tests.PreserveExceptionStackTrace2.MyMain() in xxx..cs:line 149
at MiscCS4Tests.PreserveExceptionStackTrace2.Method4() in xxx.cs:line 170
at MiscCS4Tests.PreserveExceptionStackTrace2.Method3() in xxx.cs:line 165
at MiscCS4Tests.PreserveExceptionStackTrace2.Method2() in xxx.cs:line 159
at MiscCS4Tests.PreserveExceptionStackTrace2.Method2() in xxx.cs:line 161
at MiscCS4Tests.PreserveExceptionStackTrace2.Method1() in xxx..cs:line 154
at MiscCS4Tests.PreserveExceptionStackTrace2.MyMain() in xxx..cs:line 149
Note that Method2 appears twice in the trace: once where the exception was caught, and once where it was thrown. This is undesirable but better than losing the rest of the stack trace.
Caveats:
- There are security restrictions for using reflection. Refer to the Accessing Members That Are Normally Inaccessible section in this article.
- This depends on internal implementations of the Exception class which could change. Although, if that happens, you can at least rewrite this extension method to use less efficient, but publicly supported, interfaces as described here. This involves serializing & deserializing the exception.
Monday, March 5, 2012
Examining SQL Server sessions
I recently needed to see the number of SQL Server sessions connected to a database, and what they were doing.
There are these handy stored procedures to list the current (and currently executing) sessions in a SQL Server database.
sp_who: Comes pre-installed. Lists session currently connected to a database. More info here.
But typically people prefer sp_who2, which displays more information.
sp_who2: Comes pre-installed. Lists session currently connected to a database. More info here.
But to easily see the active sessions, and what they're currently doing, you want sp_who3.
sp_who3: You need to install this yourself. (Definition is here.) Lists only sessions with a currently executing request, along with what that SQL statement is.
There are these handy stored procedures to list the current (and currently executing) sessions in a SQL Server database.
sp_who: Comes pre-installed. Lists session currently connected to a database. More info here.
But typically people prefer sp_who2, which displays more information.
sp_who2: Comes pre-installed. Lists session currently connected to a database. More info here.
But to easily see the active sessions, and what they're currently doing, you want sp_who3.
sp_who3: You need to install this yourself. (Definition is here.) Lists only sessions with a currently executing request, along with what that SQL statement is.
Tuesday, January 31, 2012
ASP.NET limits the number of form variables
Did your form post suddenly stop working?
On Dec. 29, 2011, Microsoft released a security fix through Windows Update (MS11-100). Among other things, this fix limits the maximum number of form variables, files, and JSON members in an HTTP request to 1000.
As described in http://support.microsoft.com/kb/2661403, HTTP clients that make these kinds of large requests will be denied, and an error message will appear in the web browser. The error message will usually have an HTTP 500 status code.
But the catch is, the only true indication that you're encountering this problem is the specific exception stack trace visible in the event log (or in the rendered ASP.NET page, if your web.config <
This new Microsoft limit can be configured on a per-application basis in web.config. In the <appSettings> section, add a new key for "aspnet:MaxHttpCollectionKeys" with an appropriately large value for your specific site:
There is a separate limit for JSON members:
Note: If you are using ASP.NET 1.1, the setting is adjusted by adding a DWORD value to registry keys; see http://support.microsoft.com/kb/2661403.
On Dec. 29, 2011, Microsoft released a security fix through Windows Update (MS11-100). Among other things, this fix limits the maximum number of form variables, files, and JSON members in an HTTP request to 1000.
As described in http://support.microsoft.com/kb/2661403, HTTP clients that make these kinds of large requests will be denied, and an error message will appear in the web browser. The error message will usually have an HTTP 500 status code.
But the catch is, the only true indication that you're encountering this problem is the specific exception stack trace visible in the event log (or in the rendered ASP.NET page, if your web.config <
customErrors mode="..."> allows it). An example:[InvalidOperationException: Operation is not valid due to the current state of the object.]
System.Web.HttpRequest.FillInFormCollection() +468
System.Web.HttpRequest.get_Form() +79
System.Web.HttpRequest.get_HasForm() +73
System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +54
System.Web.UI.Page.DeterminePostBackMode() +90
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +268
This new Microsoft limit can be configured on a per-application basis in web.config. In the <appSettings> section, add a new key for "aspnet:MaxHttpCollectionKeys" with an appropriately large value for your specific site:
<add key="aspnet:MaxHttpCollectionKeys" value="2000" />
There is a separate limit for JSON members:
<add key="aspnet:MaxJsonDeserializerMembers" value="2000" />
Note: If you are using ASP.NET 1.1, the setting is adjusted by adding a DWORD value to registry keys; see http://support.microsoft.com/kb/2661403.
Subscribe to:
Posts (Atom)







