每次訪問報表都需要windows驗證,這樣的報表給客戶確實很說不過去.
SSRS 可以匿名登錄的設定步驟:
環境:
開發工具:SQL Server Business Intelligence Development Studio
數據庫: SQL2008
首先確定你的Reporting Services 目錄位置
默認為: C:\Program Files\Microsoft SQL Server\MSRS11.MSSQLSERVER\Reporting Services\ReportServer
打開目錄會修改該目錄下的3個配置文件,分別為:rsreportserver.config , rssrvpolicy.config ,web.config
解決步驟:
1.打開 rsreportserver.config
修改 Configuration/Authentication/AuthenticationTypes
修改前:
<Authentication> <AuthenticationTypes> <RSWindowsNTLM/> </AuthenticationTypes> </Authentication>
修改后:
<Authentication> <AuthenticationTypes> <Custom/> </AuthenticationTypes> </Authentication>
2. 修改 web.config
<!--節點:configuration/system.web/authentication --> <!-- 修改前 --> <authentication mode="Windows" /> <identity impersonate="true" /> <!-- 修改后 --> <authentication mode="None" /> <identity impersonate="false" />
3. 從微軟下載匿名登錄的范例項目
( 下載網址 http://blog.quasarinc.com/wp-content/uploads/2012/03/Microsoft.Samples.ReportingServices.AnonymousSecurity.zip),
並且重新編譯出一個新的 Microsoft.Samples.ReportingServices.AnonymousSecurity.dll 動態庫,
范例為2010解決方案,其實里面用到的只是class1.cs文件,還有項目名稱不能變,和我們下面配置有直接關系.
打開解決方案 將 Microsoft.ReportingServices.Interfaces.dll 的引用移除,並添加本地服務器的這個文件,位置在 ..\Reporting Services\ReportServer\bin 下, (注意別把這個dll當成萬能的)
重新編譯會生成 : Microsoft.Samples.ReportingServices.AnonymousSecurity.dll 將該文件放置bin目錄下
4.再次修改 rsreportserver.config
<!--修改節點:Configuration/Extensions/Security/Extension --> <!-- 修改前 --> <Security> <Extension Name="Windows" Type="Microsoft.ReportingServices.Authorization.WindowsAuthorization, Microsoft.ReportingServices.Authorization" /> </Security> <Authentication> <Extension Name="Windows" Type="Microsoft.ReportingServices.Authentication.WindowsAuthentication, Microsoft.ReportingServices.Authorization" /> </Authentication> <!-- 修改后 --> <Security> <Extension Name="None" Type="Microsoft.Samples.ReportingServices.AnonymousSecurity.Authorization, Microsoft.Samples.ReportingServices.AnonymousSecurity" /> </Security> <Authentication> <Extension Name="None" Type="Microsoft.Samples.ReportingServices.AnonymousSecurity.AuthenticationExtension, Microsoft.Samples.ReportingServices.AnonymousSecurity" /> </Authentication>
5. 在 rssrvpolicy.config 內新增一個節點
<!-- 要增加的節點 configuration/mscorlib/security/PolicyLevel 之下 --> <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="Private_assembly" Description="This code group grants custom code full trust. "> <IMembershipCondition class="UrlMembershipCondition" version="1" Url="C:\Program Files\Microsoft SQL Server\MSRS11.MSSQLSERVER\Reporting Services\ReportServer\bin\Microsoft.Samples.ReportingServices.AnonymousSecurity.dll" />
</CodeGroup>
注意:這個Url,路徑是reporting services 目錄下新編譯的文件,不同數據庫版本,或安裝目錄不同,會有差異
6. 重新啟動 Reporting Services
完美解決,歷時半個月,這個問題終於告以段落,以后可以專心設計報表了.
以上解決方案參考於msdn上的一篇文章,做了些整理.
由於是程序員,所有手工做的事還是交給程序做,以上5個步驟,已使用程序實現:
起個名字叫: ssrs_onekey_nologin 全稱:sql server report serveics 一鍵匿名登錄配置.
主要功能,修改xml ,自己生成dll,copy至 bin目錄下.
使用說明:需錄入report services 目錄
代碼共享:

1 class Program 2 { 3 static void Main(string[] args) 4 { 5 Console.WriteLine("請輸入Reporting Services目錄:為空則與c盤默認sql2008"); 6 string a = Console.ReadLine(); 7 8 9 string basePath; 10 if (string.IsNullOrEmpty(a)) 11 { 12 basePath = @"c:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportServer"; 13 }else 14 { 15 basePath = a; 16 } 17 18 Console.WriteLine("Reporting Services 目錄為:{0}", basePath); 19 Console.WriteLine("確認請按任意鍵..."); 20 Console.ReadKey(); 21 22 string bakPath = @"c:\SSRS_noLogin_bak\" + DateTime.Now.ToString("yyyyMMddHHmmss"); 23 Directory.CreateDirectory(bakPath); 24 File.Copy(basePath + "\\rsreportserver.config", bakPath + "\\rsreportserver.config"); 25 File.Copy(basePath + "\\web.config", bakPath + "\\web.config"); 26 File.Copy(basePath + "\\rssrvpolicy.config", bakPath + "\\rssrvpolicy.config"); 27 28 Console.WriteLine("第1步開始:"); 29 Step1(basePath); 30 Console.WriteLine("第1步結束."); 31 32 Console.WriteLine("第2步開始:"); 33 Step2(basePath); 34 Console.WriteLine("第2步結束."); 35 36 Console.WriteLine("第3步開始:"); 37 Step3(basePath); 38 Console.WriteLine("第3步結束."); 39 40 Console.WriteLine("第4步開始:"); 41 Step4(basePath); 42 Console.WriteLine("第4步結束."); 43 44 Console.WriteLine("第5步開始:"); 45 Step5(basePath); 46 Console.WriteLine("第5步結束."); 47 48 Console.WriteLine("完成"); 49 Console.ReadKey(); 50 } 51 52 static void Step1(string basePath) 53 { 54 string file = basePath + "\\rsreportserver.config"; 55 XmlDocument doc = new XmlDocument(); 56 doc.Load(file); //Configuration 57 XmlNode xn = doc.SelectSingleNode("Configuration/Authentication/AuthenticationTypes"); 58 XmlNode oldXn = xn.SelectSingleNode("RSWindowsNTLM"); 59 if (oldXn == null) 60 { 61 Console.WriteLine("未找到RSWindowsNTLM,或已更改"); 62 } 63 else 64 { 65 XmlNode newXn = doc.CreateElement("Custom"); 66 xn.ReplaceChild(newXn, oldXn); 67 } 68 doc.Save(file); 69 70 } 71 static void Step2(string basePath) 72 { 73 XmlDocument doc = new XmlDocument(); 74 string file = basePath + "\\web.config"; 75 doc.Load(file); 76 XmlNode xn2 = doc.SelectSingleNode("configuration/system.web/authentication"); 77 XmlElement xm2 = (XmlElement)xn2; 78 xm2.SetAttribute("mode", "None"); 79 80 XmlNode xn3 = doc.SelectSingleNode("configuration/system.web/identity"); 81 XmlElement xm3 = (XmlElement)xn3; 82 xm3.SetAttribute("impersonate", "false"); 83 84 doc.Save(file); 85 } 86 static void Step3(string basePath) 87 { 88 CSharpCodeProvider objCSharpCodePrivoder = new CSharpCodeProvider(); 89 CompilerParameters objCompilerParameters = new CompilerParameters(); 90 objCompilerParameters.ReferencedAssemblies.Add("System.dll"); 91 objCompilerParameters.ReferencedAssemblies.Add(basePath + @"\bin\Microsoft.ReportingServices.Interfaces.dll"); 92 string strSourceCode = Resources.Class1; 93 objCompilerParameters.GenerateInMemory = false; 94 objCompilerParameters.OutputAssembly = "Microsoft.Samples.ReportingServices.AnonymousSecurity.dll"; 95 CompilerResults cr = objCSharpCodePrivoder.CompileAssemblyFromSource(objCompilerParameters, strSourceCode); 96 if (cr.Errors.HasErrors) 97 { 98 string strErrorMsg = cr.Errors.Count.ToString() + " Errors:"; 99 for (int x = 0; x < cr.Errors.Count; x++) 100 { 101 strErrorMsg = strErrorMsg + "/r/nLine: " + 102 cr.Errors[x].Line.ToString() + " - " + 103 cr.Errors[x].ErrorText; 104 } 105 Console.WriteLine(strErrorMsg); 106 return; 107 } 108 File.Copy("Microsoft.Samples.ReportingServices.AnonymousSecurity.dll", basePath + @"\bin\Microsoft.Samples.ReportingServices.AnonymousSecurity.dll", true); 109 File.Delete("Microsoft.Samples.ReportingServices.AnonymousSecurity.dll"); 110 } 111 static void Step4(string basePath) 112 { 113 XmlDocument doc = new XmlDocument(); 114 string file = basePath + "\\rsreportserver.config"; 115 doc.Load(file); 116 XmlNode xn2 = doc.SelectSingleNode("Configuration/Extensions/Security/Extension"); 117 XmlElement xm2 = (XmlElement)xn2; 118 xm2.SetAttribute("Name", "None"); 119 xm2.SetAttribute("Type", "Microsoft.Samples.ReportingServices.AnonymousSecurity.Authorization, Microsoft.Samples.ReportingServices.AnonymousSecurity"); 120 121 XmlNode xn3 = doc.SelectSingleNode("Configuration/Extensions/Authentication/Extension"); 122 XmlElement xm3 = (XmlElement)xn3; 123 xm3.SetAttribute("Name", "None"); 124 xm3.SetAttribute("Type", "Microsoft.Samples.ReportingServices.AnonymousSecurity.AuthenticationExtension, Microsoft.Samples.ReportingServices.AnonymousSecurity"); 125 126 doc.Save(file); 127 } 128 129 static void Step5(string basePath) 130 { 131 XmlDocument doc = new XmlDocument(); 132 string file = basePath + "\\rssrvpolicy.config"; 133 doc.Load(file); 134 XmlNode xn1 = doc.SelectSingleNode("configuration/mscorlib/security/PolicyLevel/CodeGroup[@class=UnionCodeGroup]"); 135 if (xn1 != null) 136 { 137 //已添加 138 } 139 else 140 { 141 XmlNode xn = doc.SelectSingleNode("configuration/mscorlib/security/policy/PolicyLevel"); 142 XmlElement xe = doc.CreateElement("CodeGroup"); 143 xe.SetAttribute("class", "UnionCodeGroup"); 144 xe.SetAttribute("version", "1"); 145 xe.SetAttribute("PermissionSetName", "FullTrust"); 146 xe.SetAttribute("Name", "Private_assembly"); 147 xe.SetAttribute("Description", "This code group grants custom code full trust."); 148 149 XmlElement xe2 = doc.CreateElement("IMembershipCondition"); 150 xe2.SetAttribute("class", "UrlMembershipCondition"); 151 xe2.SetAttribute("version", "1"); 152 xe2.SetAttribute("Url", basePath + @"\bin\Microsoft.Samples.ReportingServices.AnonymousSecurity.dll"); 153 154 xe.AppendChild(xe2); 155 xn.AppendChild(xe); 156 } 157 doc.Save(file); 158 } 159 160 } 161 }
程序共享:
解決后測試頁的展示: