Thursday, January 15, 2015

Problem with 401 Unauthorized error when anonymous user tries to open xlsx file

In Sharepoint 2010 when anonymous user tries to open xlsx file the following error may occur:

401 Unauthorized

At the same time old xsl files are opened well. Several solutions for this problems are mentioned there: http://support.microsoft.com/kb/2498047. However if they are not good for your scenario, you may use solution described below. The reason of the problem is the following: for several Excel files (by default they are xlsx, xlsb and xls) Sharepoint generates special link which points to the handler /_layouts/xlviewer.aspx?id=… instead of the link to original file. And when anonymous user tries to open xslx file, we get 401 Unauthorized exception because /_layouts/xlviewer.aspx page is not available for anonymous by default. In order to fix the problem we may do the following.

Excel files for which Sharepoint creates dynamic links are specified in serverfilesExcelServer.xml file which is located in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML folder. By default it looks like this:

   1: <?xml version="1.0" encoding="utf-8" ?>
   2:  
   3: <!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
   4:  
   5: <ServerFiles>
   6:     <Mapping FileExtension="xlsx" RedirectUrlTemplate="/_layouts/xlviewer.aspx?id=|0"
   7:     NoGetRedirect="TRUE" CreateRedirectUrlTemplate="/_layouts/xlviewer.aspx?new=1"/>
   8:     <Mapping FileExtension="xlsb" RedirectUrlTemplate="/_layouts/xlviewer.aspx?id=|0"
   9:     NoGetRedirect="TRUE" CreateRedirectUrlTemplate="/_layouts/xlviewer.aspx?new=1"/>
  10:     <Mapping FileExtension="xlsm" RedirectUrlTemplate="/_layouts/xlviewer.aspx?id=|0"
  11:     NoGetRedirect="TRUE" CreateRedirectUrlTemplate="/_layouts/xlviewer.aspx?new=1"/>
  12:     <Mapping FileExtension="ods" RedirectUrlTemplate="/_layouts/xlviewer.aspx?id=|0"
  13:     NoGetRedirect="TRUE" CreateRedirectUrlTemplate="/_layouts/CreateNewDocument.aspx?id=|0"/>
  14: </ServerFiles>

After we will comment line with xlsx extension, Sharepoint will use regular links which will point to files themselves:

   1: <?xml version="1.0" encoding="utf-8" ?>
   2:  
   3: <!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
   4:  
   5: <ServerFiles>
   6:     <!--<Mapping FileExtension="xlsx" RedirectUrlTemplate="/_layouts/xlviewer.aspx?id=|0"
   7:     NoGetRedirect="TRUE" CreateRedirectUrlTemplate="/_layouts/xlviewer.aspx?new=1"/>-->
   8:     <Mapping FileExtension="xlsb" RedirectUrlTemplate="/_layouts/xlviewer.aspx?id=|0"
   9:     NoGetRedirect="TRUE" CreateRedirectUrlTemplate="/_layouts/xlviewer.aspx?new=1"/>
  10:     <Mapping FileExtension="xlsm" RedirectUrlTemplate="/_layouts/xlviewer.aspx?id=|0"
  11:     NoGetRedirect="TRUE" CreateRedirectUrlTemplate="/_layouts/xlviewer.aspx?new=1"/>
  12:     <Mapping FileExtension="ods" RedirectUrlTemplate="/_layouts/xlviewer.aspx?id=|0"
  13:     NoGetRedirect="TRUE" CreateRedirectUrlTemplate="/_layouts/CreateNewDocument.aspx?id=|0"/>
  14: </ServerFiles>

And after that problem should disappear. Hope it will help you in your work.

2 comments:

  1. Great!!!! it works perfect for me....

    ReplyDelete
  2. Thanks a lot. Works like a charm after app pool recycle. The MS Knowledge Base article doesn't have a clue.

    Juha

    ReplyDelete