{"id":431,"date":"2010-09-28T12:31:34","date_gmt":"2010-09-28T17:31:34","guid":{"rendered":"http:\/\/www.uv.mx\/personal\/gvera\/2010\/09\/28\/sharepoint-login-prompt-when-accessing-files-in-a-document-library\/"},"modified":"2013-01-14T14:30:45","modified_gmt":"2013-01-14T20:30:45","slug":"sharepoint-login-prompt-when-accessing-files-in-a-document-library","status":"publish","type":"post","link":"https:\/\/www.uv.mx\/personal\/gvera\/2010\/09\/28\/sharepoint-login-prompt-when-accessing-files-in-a-document-library\/","title":{"rendered":"SharePoint login prompt when accessing files in a Document Library Solution"},"content":{"rendered":"<p style=\"text-align: center\"><a href=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/image1.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-width: 0px\" src=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/image_thumb.png\" alt=\"image\" width=\"329\" height=\"200\" border=\"0\" \/><\/a><\/p>\n<p style=\"text-align: right\"><a title=\"Ver la entrada en espa\u00f1ol\" href=\"http:\/\/www.uv.mx\/personal\/gvera\/2010\/09\/28\/sharepoint-pide-credenciales-al-acceder-archivos-en-una-biblioteca-de-documentos\/\">Espa\u00f1ol<\/a> | English<\/p>\n<h3><span style=\"color: #993300\"><strong>UPDATED 29-SEP-2011: Fixed\u00a0for anonymous sites and IE. Really Works!<\/strong><\/span><\/h3>\n<p>Since long ago we faced a problem here at the University Of Veracruz, with some of the out-of-the-box funcionality in WSS, MOSS 2007 and SharePoint Server 2010.<\/p>\n<p>As we all know, in order to login in a non anonymous SharePoint Web Site, we have to provide our domain\/username credentials. That is ok if our site has not the \u201callow anonymous\u201d option enabled. But what happens when we click on an Office document (such as Word or Excel file) using Internet Explorer?<\/p>\n<p><em>Any time we try to open a file, we are again, prompted for the credentials. This happens even if the user was the creator of the file or the \u201callow anonymous\u201d option is enabled.<\/em><\/p>\n<p>What does Microsoft has to say about it?<\/p>\n<blockquote><p>This is by design.<\/p><\/blockquote>\n<p>Some references of this problem from Microsoft&#8217;s Web sites:<\/p>\n<p><strong>Multiple Logon while open office Document from SharePoint<\/strong><br \/>\n<a title=\"http:\/\/blogs.technet.com\/b\/steve_chen\/archive\/2010\/06\/25\/multiple-logon-while-open-office-document-from-sharepoint.aspx\" href=\"http:\/\/blogs.technet.com\/b\/steve_chen\/archive\/2010\/06\/25\/multiple-logon-while-open-office-document-from-sharepoint.aspx\">http:\/\/blogs.technet.com\/b\/steve_chen\/archive\/2010\/06\/25\/multiple-logon-while-open-office-document-from-sharepoint.aspx<\/a><\/p>\n<p><strong>Office: Authentication prompts when opening Microsoft Office documents<\/strong><br \/>\n<a href=\"http:\/\/support.microsoft.com\/kb\/2019105\" target=\"_blank\">http:\/\/support.microsoft.com\/kb\/2019105<\/a><\/p>\n<p><strong>How documents are opened from a Web site in Office 2003<br \/>\n<\/strong><a href=\"http:\/\/support.microsoft.com\/kb\/838028\" target=\"_blank\">http:\/\/support.microsoft.com\/kb\/838028<\/a><\/p>\n<p>Are you crazy?<\/p>\n<p>What is happening is that Office is trying to be so smart that needs to know who you are in order to provide some functionality for working with online documents inside the Office suite.<\/p>\n<p>&#8211; Me: That\u2019s fine, but at least give me the option to disable this behavior from SharePoint Administration.<\/p>\n<p>&#8211; Office-SharePoint: No. You cannot.<\/p>\n<h3>Explanation of this behavior<\/h3>\n<p>Well, if you try to open an Office file directly from a remote place, Office wants to know who the hell you are. If the server responses with the<\/p>\n<ul>\n<li><strong><em>Microsoft Office Protocol Discovery<\/em><\/strong> or a<\/li>\n<li><strong><em>FrontPage Protocol<\/em><\/strong> or a<\/li>\n<li><strong><em>WebDav Protocol<\/em><\/strong><\/li>\n<\/ul>\n<p>then it ask you for credentials. Not only Office does this. If you try to open a library as a HTTP SharePoint Folder View, Windows (something to do with how IE handles downloads) does the same. The request comes from one of these protocols so the Microsoft client app have to ask for credentials. It is by design. You can see this yourself if you catch the <em>Request.UserAgent<\/em> string at the moment you open a file from SharePoint.<\/p>\n<p>You can create an HttpModule that searches for the <em>Request.UserAgent<\/em> string, so if you find one of these protocols, then send a 200 status code in the response. The problem here is that you are disabling not only logins prompts for documents, but for the entire client integration feature (opening files from Word, Excel or folder views in libraries). This is not what we want.<\/p>\n<p><em><strong>We want to be able to use client integration, it&#8217;s a nice feature, but we do not want to be prompted inside our document libraries.<\/strong><\/em><\/p>\n<h3>Solution WSS 3.0 and MOSS2007<\/h3>\n<p>As I said before, there is not a solution for this problem since this behavior is by design, but that is not going to stop us, is it? Here you have a workaround.<\/p>\n<p><!--more--> After searching all over the Web with no results, I decided to face the problem myself. If you notice, there is an option inside the file dropdown menu called \u201cSent To-&gt;Download a Copy\u201d. This options does exactly what we are trying to accomplish. It calls a file inside layouts folder called <em><strong>download.aspx<\/strong><\/em>. This file serves a file from SP content database using this code:<\/p>\n<p>[js]<br \/>\n\/\/ This inside download.cs file<br \/>\nResponse.AddHeader(&quot;Content-Disposition&quot;, &quot;attachment;filename=&quot; + filename);<br \/>\n\/\/<br \/>\n[\/js]<\/p>\n<p>That&#8217;s why this option does not open the file directly on the server (the attachment string does it all).<\/p>\n<p><strong><em>The problem here is that this download.aspx file needs you to be authenticated. So if your site is anonymous, the option \u201cSent To-&gt;Download a Copy\u201d will ask you for credentials. It&#8217;s stupid I know, but it does. They fix this on SPS2010 though.<\/em><\/strong><\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/image2.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-width: 0px\" src=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/image_thumb1.png\" alt=\"image\" width=\"299\" height=\"132\" border=\"0\" \/><\/a><\/p>\n<p>Don&#8217;t worry. We are going to handle the anonymous stuff later on (See below on Anonymous section)<\/p>\n<p>So, where is the code for that \u00abDownload a copy\u00bb option?<\/p>\n<p>Exactly, as you are guessing, in a JavaScript file called \u201cCORE.JS\u201d located in C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\template\\layouts\\[some numbers] folder.<\/p>\n<p>1. Make a backup of your CORE.JS file.<\/p>\n<p>2. Find this line in the CORE.JS file:<\/p>\n<p>[js]<br \/>\n\/*<br \/>\nFind this function<br \/>\n*\/<br \/>\nfunction DispDocItemEx(ele, fTransformServiceOn, fShouldTransformExtension, fTransformHandleUrl, strProgId)<br \/>\n\/\/<br \/>\n\/\/<br \/>\n[\/js]<\/p>\n<p>3.Add this just below it <strong>UPDATED (29 SEP 2011)<\/strong>:<\/p>\n<p>[js]<\/p>\n<p>\t\/*<br \/>\n\t\/ Agregado por Memo Vera para evitar que abra las App de Office.<br \/>\n\t\/ 28 SEP 2010<br \/>\n\t\/ Modificado el 29 SEP 2011<br \/>\n\t*\/<br \/>\n\tvar office_extensions = \/(.docx?|.pptx?|xlsx?|md[ab]|mp[pt])$\/i;<br \/>\n\tif (office_extensions.test(ele)) {<br \/>\n\t\tSTSNavigate(ctx.HttpRoot + &quot;\/_layouts\/download.aspx?&quot; + &quot;SourceUrl=&quot; + escapeProperly(ele.href));<br \/>\n\t\treturn false;<br \/>\n\t}<br \/>\n\tif (browseris.ie)<br \/>\n\t\tevent.cancelBubble = false;<br \/>\n\t\treturn true;<br \/>\n\t\/*<br \/>\n\t\/ FIN modificacion<br \/>\n\t*\/<\/p>\n<p>[\/js]<\/p>\n<p>Leave the rest of the function just as it is. No need to change anything else.<\/p>\n<p>Don\u2019t worry, no need to restart your SharePoint Server or any service. No need to add your SharePoint Server URL to your Trusted Sites (although I recommend it).<\/p>\n<p>There you go. Refresh your Web Page and make sure you clean your local Web Browser cache so you get the new version of the CORE.JS file.<\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/image3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-width: 0px\" src=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/image_thumb2.png\" alt=\"image\" width=\"595\" height=\"183\" border=\"0\" \/><\/a><\/p>\n<p>I have this working on my environment with WSS 3.0 with no problem. Everyone is happy, can use SharePoint Client Integration and those login prompts for online editing are gone. If I want to edit a document online, I select the option \u201cEdit in Microsoft Word\u201d or open the file from Word App.<\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/image4.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-width: 0px\" src=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/image_thumb3.png\" alt=\"image\" width=\"286\" height=\"120\" border=\"0\" \/><\/a><\/p>\n<h3>Anonymous sites browsing with IE on MOSS 2007 and WSS 3.0<\/h3>\n<p>Like I wrote before, we are using the <em>C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\template\\layouts\\download.aspx<\/em> file witch is the one that serves files from SP content database. The problem with anonymous sites and this file, is that it needs you to be authenticated. As crazy as it might sound, it is true. Try it yourself on a clean SP box:<\/p>\n<p>Create an anonymous site, upload some Office documents and log off. Open IE and visit your site as anonymous and click on \u201cSent To-&gt;Download a Copy\u201d. The box will ask for your credentials. Just crazy.<\/p>\n<p><a href=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/11\/image44.png\"><img loading=\"lazy\" decoding=\"async\" style=\"margin: 0px;padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px\" src=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/11\/image_thumb44.png\" alt=\"image\" width=\"475\" height=\"285\" border=\"0\" \/><\/a><\/p>\n<p>Microsoft fix this on SPS2010 though, so you do not need to do this on 2010 boxes.<\/p>\n<p>We have to add just a simple line of code inside this file that tells SP that we dont need to be authenticated.<\/p>\n<p>1. Open your <em>C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\template\\layouts\\download.aspx <\/em>file. I dont have to tell you to make a backup first.<\/p>\n<p>2. Make some modifications, so your file will end like this:<\/p>\n<p>[csharp]<\/p>\n<p>&lt;script runat=&quot;server&quot; type=&quot;text\/C#&quot;&gt;<br \/>\n\t\/*<br \/>\n\t\/ Cambio por Memo Vera y no pedira autenticacion<br \/>\n\t\/ 29 SEP 2011<br \/>\n\t*\/<br \/>\n\tprotected override bool AllowAnonymousAccess<br \/>\n\t{<br \/>\n\t\tget{<br \/>\n\t\t\treturn true;<br \/>\n\t\t}<br \/>\n\t}<br \/>\n&lt;\/script&gt;<\/p>\n<p>[\/csharp]<\/p>\n<p>3. Nice! Save your file.<\/p>\n<p>4. Try it! Visit your site anonymously and click on a file or use the option Sent To-&gt;Download a Copy\u201d.<\/p>\n<p><a href=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/11\/image42.png\"><img loading=\"lazy\" decoding=\"async\" style=\"margin: 0px;padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px\" src=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/11\/image_thumb42.png\" alt=\"image\" width=\"475\" height=\"227\" border=\"0\" \/><\/a><\/p>\n<p>Beautiful, isn\u2019t it?<\/p>\n<p><a href=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/11\/image43.png\"><img loading=\"lazy\" decoding=\"async\" style=\"margin: 0px;padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px\" src=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/11\/image_thumb43.png\" alt=\"image\" width=\"475\" height=\"134\" border=\"0\" \/><\/a><\/p>\n<h3>Solution SharePoint Server 2010<\/h3>\n<p>In SPS 2010 is slightly different.<\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/1-300x119.jpg\" alt=\"\" width=\"300\" height=\"119\" \/><\/a><\/p>\n<p>The JavaScript file called <strong>\u201cinit.js\u201d<\/strong> located in \\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\1033 folder.<\/p>\n<p>The functions inside this file reffer to the core.js file. This init.js es minified (from init.debug.js) so it won&#8217;t be easy to edit. You have to be carefull.<\/p>\n<p>1. Make a backup of your init.js file.<\/p>\n<p>2. Find this line in the init.js file:<\/p>\n<p>[js]<\/p>\n<p>function DispEx(o,n,e,a,d,i,g,m,k,b,h,j,f,c,l){<\/p>\n<p>[\/js]<\/p>\n<p>3. Add this just right to it (remove the line breaks if necessary):<\/p>\n<p>[js]<\/p>\n<p>\/*Agregado por Memo Vera para evitar que abra las App de Office. 18 NOV 2010.*\/STSNavigate(ctx.HttpRoot + &quot;\/_layouts\/download.aspx?SourceUrl=&quot; + o);return false;<\/p>\n<p>[\/js]<\/p>\n<p>Update: Excel files have a problem with SPS2010. They wont download until you log in. They do not even have the context menu \u00abDownload a copy\u00bb enabled. I also have a problem with Office Web Apps. Give me sometime to figure it out this part. In the mean time, i suggest you to upload those files within a zip file.<\/p>\n<p>This will only work for logged on users.<\/p>\n<p>1. Find this line in the init.js file:<\/p>\n<p>[js]<\/p>\n<p>VerifyHref(e,d,b,c,a){<\/p>\n<p>[\/js]<\/p>\n<p>2. Add this just right to it (remove the line breaks if necessary):<\/p>\n<p>[js]<\/p>\n<p>\/*Agregado por Memo Vera para evitar que abra las App de Office. 29 AUG 2011.*\/return false;<\/p>\n<p>[\/js]<\/p>\n<p>Leave the rest of the function just as it is. No need to change anything else.<\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/2-300x162.jpg\" alt=\"\" width=\"300\" height=\"162\" \/><\/a><\/p>\n<p>This applies for all Office files and it&#8217;s working also on others browsers like Firefox.<\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/3.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2010\/09\/3-300x136.jpg\" alt=\"\" width=\"300\" height=\"136\" \/><\/a><\/p>\n<p style=\"text-align: justify\">Hope it helps you.<\/p>\n<h3>Issues<\/h3>\n<p>Well, the only one I can think of is when some SharePoint update or patch replaces the CORE.JS file. No problem because we added just a couple of lines of code. We can certainly add them back.<\/p>\n<p>Try it yourself and let me know if this has worked for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Espa\u00f1ol | English UPDATED 29-SEP-2011: Fixed\u00a0for anonymous sites and IE. Really Works! Since long ago we faced a problem here at the University Of Veracruz, with some of the out-of-the-box funcionality in WSS, MOSS 2007 and SharePoint Server 2010. As we all know, in order to login in a non anonymous SharePoint Web Site, we&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,21],"tags":[11,28,13],"class_list":["post-431","post","type-post","status-publish","format-standard","hentry","category-blog","category-sharepoint","tag-articulos-2","tag-sharepoint-2","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/posts\/431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/comments?post=431"}],"version-history":[{"count":0,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/posts\/431\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/media?parent=431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/categories?post=431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/tags?post=431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}