IT俱乐部 MsSql SQL Server Reporting Services 匿名登录的问题及解决方案

SQL Server Reporting Services 匿名登录的问题及解决方案

每次访问报表都需要windows验证,这样的报表给客户确实很说不过去.

SSRS 可以匿名登录的设定步骤:

环境:

  开发工具:SQL Server Business Intelligence Development Studio

  数据库: SQL2008

首先确定你的Reporting Services 目录位置

默认为:C:Program FilesMicrosoft SQL ServerMSRS11.MSSQLSERVERReporting ServicesReportServer

打开目录会修改该目录下的3个配置文件,分别为:rsreportserver.config ,rssrvpolicy.config ,web.config

解决步骤:

  1.打开rsreportserver.config

   修改Configuration/Authentication/AuthenticationTypes

   修改前:

1
<authentication><authenticationtypes><rswindowsntlm></rswindowsntlm></authenticationtypes></authentication>

修改后:

1
<authentication><authenticationtypes><custom></custom></authenticationtypes></authentication>

2. 修改web.config

1
<authentication mode="Windows"></authentication><identity impersonate="true"></identity><authentication mode="None"></authentication><identity impersonate="false"></identity>

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 ServicesReportServerbin 下, (注意别把这个dll当成万能的)

重新编译会生成 :Microsoft.Samples.ReportingServices.AnonymousSecurity.dll 将该文件放置bin目录下

4.再次修改rsreportserver.config

1
<security><extension name="Windows" type="Microsoft.ReportingServices.Authorization.WindowsAuthorization, Microsoft.ReportingServices.Authorization"></extension></security><authentication><extension name="Windows" type="Microsoft.ReportingServices.Authentication.WindowsAuthentication, Microsoft.ReportingServices.Authorization"></extension></authentication><security><extension name="None" type="Microsoft.Samples.ReportingServices.AnonymousSecurity.Authorization, Microsoft.Samples.ReportingServices.AnonymousSecurity"></extension></security><authentication><extension name="None" type="Microsoft.Samples.ReportingServices.AnonymousSecurity.AuthenticationExtension, Microsoft.Samples.ReportingServices.AnonymousSecurity"></extension></authentication>

5. 在 rssrvpolicy.config 内新增一个节点

1
<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 FilesMicrosoft SQL ServerMSRS11.MSSQLSERVERReporting ServicesReportServerbinMicrosoft.Samples.ReportingServices.AnonymousSecurity.dll"></imembershipcondition></codegroup>

注意:这个Url,路径是reporting services 目录下新编译的文件,不同数据库版本,或安装目录不同,会有差异

6. 重新启动 Reporting Services

完美解决,历时半个月,这个问题终于告以段落,以后可以专心设计报表了.

以上解决方案参考于msdn上的一篇文章,做了些整理.

由于是程序员,所有手工做的事还是交给程序做,以上5个步骤,已使用程序实现:

起个名字叫:ssrs_onekey_nologin 全称:sql server report serveics 一键匿名登录配置.

主要功能,修改xml ,自己生成dll,copy至 bin目录下.

使用说明:需录入report services 目录

代码共享:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class Program
      {
          static void Main(string[] args)
          {
              Console.WriteLine("请输入Reporting Services目录:为空则与c盘默认sql2008");
              string a = Console.ReadLine();
   
   
              string basePath;
             if (string.IsNullOrEmpty(a))
             {
                basePath = @"c:Program FilesMicrosoft SQL ServerMSRS10.MSSQLSERVERReporting ServicesReportServer";
             }else
            {
                basePath = a;
             }
 
            Console.WriteLine("Reporting Services 目录为:{0}", basePath);
            Console.WriteLine("确认请按任意键...");
            Console.ReadKey();
 
            string bakPath = @"c:SSRS_noLogin_bak" + DateTime.Now.ToString("yyyyMMddHHmmss");
           Directory.CreateDirectory(bakPath);
           File.Copy(basePath + "\rsreportserver.config", bakPath + "\rsreportserver.config");
           File.Copy(basePath + "\web.config", bakPath + "\web.config");
            File.Copy(basePath + "\rssrvpolicy.config", bakPath + "\rssrvpolicy.config");
           
           Console.WriteLine("第1步开始:");
           Step1(basePath);
           Console.WriteLine("第1步结束.");
 
           Console.WriteLine("第2步开始:");
           Step2(basePath);
           Console.WriteLine("第2步结束.");
 
            Console.WriteLine("第3步开始:");
            Step3(basePath);
           Console.WriteLine("第3步结束.");
 
           Console.WriteLine("第4步开始:");
            Step4(basePath);
            Console.WriteLine("第4步结束.");
 
           Console.WriteLine("第5步开始:");
            Step5(basePath);
            Console.WriteLine("第5步结束.");
 
            Console.WriteLine("完成");
          Console.ReadKey();
        }
 
        static void Step1(string basePath)
        {
            string file = basePath + "\rsreportserver.config";
            XmlDocument doc = new XmlDocument();
            doc.Load(file);                  //Configuration
            XmlNode xn = doc.SelectSingleNode("Configuration/Authentication/AuthenticationTypes");
            XmlNode oldXn = xn.SelectSingleNode("RSWindowsNTLM");
            if (oldXn == null)
            {
                Console.WriteLine("未找到RSWindowsNTLM,或已更改");
           }
           else
          {
               XmlNode newXn = doc.CreateElement("Custom");
               xn.ReplaceChild(newXn, oldXn);
            }
             doc.Save(file);
          
        }
       static void Step2(string basePath)
        {
            XmlDocument doc = new XmlDocument();
            string file = basePath + "\web.config";
            doc.Load(file);
           XmlNode xn2 = doc.SelectSingleNode("configuration/system.web/authentication");
            XmlElement xm2 = (XmlElement)xn2;
             xm2.SetAttribute("mode", "None");
 
           XmlNode xn3 = doc.SelectSingleNode("configuration/system.web/identity");
          XmlElement xm3 = (XmlElement)xn3;
           xm3.SetAttribute("impersonate", "false");
 
           doc.Save(file);
       }
         static void Step3(string basePath)
         {
           CSharpCodeProvider objCSharpCodePrivoder = new CSharpCodeProvider();
            CompilerParameters objCompilerParameters = new CompilerParameters();
            objCompilerParameters.ReferencedAssemblies.Add("System.dll");
            objCompilerParameters.ReferencedAssemblies.Add(basePath + @"binMicrosoft.ReportingServices.Interfaces.dll");
            string strSourceCode = Resources.Class1;
            objCompilerParameters.GenerateInMemory = false;
           objCompilerParameters.OutputAssembly = "Microsoft.Samples.ReportingServices.AnonymousSecurity.dll";
           CompilerResults cr = objCSharpCodePrivoder.CompileAssemblyFromSource(objCompilerParameters, strSourceCode);
            if (cr.Errors.HasErrors)
           {
                string strErrorMsg = cr.Errors.Count.ToString() + " Errors:";
                for (int x = 0; x

程序共享:

下载

解决后测试页的展示:

到此这篇关于关于 SQL Server Reporting Services 匿名登录的解决方案的文章就介绍到这了,更多相关SQL Server Reporting Services内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/database/mssql/2203.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部