zoukankan      html  css  js  c++  java
  • 关于 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

       修改前:  

    <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 ServicesReportServerin  下, (注意别把这个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 FilesMicrosoft SQL ServerMSRS11.MSSQLSERVERReporting ServicesReportServerinMicrosoft.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 FilesMicrosoft SQL ServerMSRS10.MSSQLSERVERReporting ServicesReportServer";
     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 + @"inMicrosoft.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 + @"inMicrosoft.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 + @"inMicrosoft.Samples.ReportingServices.AnonymousSecurity.dll");
    153 
    154                 xe.AppendChild(xe2);
    155                 xn.AppendChild(xe);
    156             }
    157             doc.Save(file);
    158         }
    159 
    160     }
    161 }
    ssrs onkey no login

    程序共享:

     下载

     解决后测试页的展示:

      

  • 相关阅读:
    break (Statements) – JavaScript 中文开发手册
    :first-of-type (Selectors) – CSS 中文开发手册
    no-new-symbol (Rules) – Eslint 中文开发手册
    Null-terminated byte strings (Strings) – C 中文开发手册
    HTML DOM Time 对象
    Java 实例 – 向文件中追加数据
    HTML DOM Hidden type 属性
    在Java中扩展原始转换
    字体变位 | font-variant-position (Fonts) – CSS 中文开发手册
    逆波兰计算器完整版
  • 原文地址:https://www.cnblogs.com/xtdhb/p/4000354.html
Copyright © 2011-2022 走看看