亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

SQL Server BI Step by Step SSRS 2----SQL Ser

系統 2003 0

??? SQL SERVER 2008中,Reporting Service不再依賴于IIS,這帶來很多利處,不過這也意味著不能夠直接通過配置IIS的虛擬目錄部署來實現匿名訪問了。下面我們就看一下在SSRS 2008中怎么能夠實現報表的“匿名訪問”,不過對于一個正式項目來說, 建議不要并且從不允許匿名來訪問報表
??? 1. 實現 IReportServerCredentials 接口
??????? 對于使用Asp.Net的ReportViewer控件,實現IReportServerCredentials接口來實現自定義身份驗證,然后通過設置成ReportView的屬性ServerReport.ReportServerCredentials。此接口的定義:

  1. public ? interface ?IReportServerCredentials ??
  2. { ??
  3. ????WindowsIdentity?ImpersonationUser?{? get ;?} ??
  4. ????ICredentials?NetworkCredentials?{? get ;?} ??
  5. ???? bool ?GetFormsCredentials( out ?Cookie?authCookie,? out ? string ?userName,? out ? string ?password,? out ? string ?authority); ??
  6. }??

??????? 此接口定義了三種身份驗證的方式來訪問Report Server,可以單獨使用,也可以組合使用這三種方式。
??????? ImpersonationUser:ReportView在每次WebRequest請求到ReportServer前模擬的一個WindowsIdentity,實際上會調用這個屬性的 WindowsIdentity.Impersonate 方法來完成。如果此屬性返回null的話,則默認使用當前線程用戶。
??????? NetworkCredentials: 此屬性的值將會經由 WebRequest.Credentials 屬性直接傳遞給WebRequest,如果返回null的話,則默認是 CredentialCache.DefaultCredentials ,使用當前上下文的系統憑據,這也是通常我們使用的方式。
??????? GetFormsCredentials:這是ReportServer特有的認證體系,如果返回true的話,輸出參數將用來調用ReportServer上的 LogonUser 方法,這個方法是用來支持服務器上的 安全擴展插件


??????? 這個接口是如何被使用的呢,我們從report viewer說起。當ASPX page頁面執行時,ReportView控件并不是一次性的請求ReportServer。這其間其實需要通過ReportViewer HTTP handler多次請求Report Server.就比如報表中顯示一個圖片,在客戶端生成的html中有圖片標簽,對于其中的圖片會請求ReportView控件,ReportView收到請求后會重新請求ReportServer索要這個圖片,ReportServer這時還需要判斷當前請求的用戶是否和初始的用戶一一致,如果一致才會返回圖片。其它的例如ReportView提供的打印,導出也是同樣的原理。
?????? ReportView控件的IReportServerCredentials的實例的屬性,存儲在Asp.net SessionState中,這樣即保證了安全性,又能夠即時的獲取到認證信息。不過這個接口提供的靈活性使我們在設置這個憑據時更加靈活,我們可以如下實現:
??????

  1. [Serializable] ??
  2. class ?MyConfigFileCredentials?:?IReportServerCredentials ??
  3. { ??
  4. ???? public ?MyConfigFileCredentials() ??
  5. ????{ ??
  6. ????} ??
  7. ? ??
  8. ???? public ?WindowsIdentity?ImpersonationUser ??
  9. ????{ ??
  10. ???????? get ?{? return ? null ;?} ??
  11. ????} ??
  12. ? ??
  13. ???? public ?ICredentials?NetworkCredentials ??
  14. ????{ ??
  15. ???????? get ??
  16. ????????{ ??
  17. ???????????? return ? new ?NetworkCredential( ??
  18. ????????????????ConfigurationManager.AppSettings[ "MyUserName" ], ??
  19. ????????????????ConfigurationManager.AppSettings[ "MyPassword" ]); ??
  20. ????????} ??
  21. ????} ??
  22. ? ??
  23. ???? public ? bool ?GetFormsCredentials( out ?Cookie?authCookie,? out ? string ?userName,? out ? string ?password,? out ? string ?authority) ??
  24. ????{ ??
  25. ????????authCookie?=? null ; ??
  26. ????????userName?=? null ; ??
  27. ????????password?=? null ; ??
  28. ????????authority?=? null ; ??
  29. ????} ??
  30. }???

??????? 上面我們只提供第二種認證方式,創建一個NetwrokCredential實例,并且采用配置文件中存儲的用戶名和密碼,可以在后期修改。在配置文件中創建兩個參數的值為能夠正常訪問此報表的帳號和密碼,然后給賦值給ReportView的屬性即可:
????????

  1. ReportViewer1.ServerReport.ReportServerCredentials ?=? new ?MyConfigFileCredentials();??

???????? 這樣,當你瀏覽報表程序時,就不會提示輸入用戶名和密碼了。或許你看到這里應該也意識到了,我們所說的匿名訪問報表,并不是說報表設置給了everyone都可以訪問,而是說我們包裝了一下,省略了用戶認證這一步,而模擬成了一個可以訪問的用戶,來實現的“匿名訪問”。其實在先前使用IIS作為報表服務器的時候,也是通過在IIS中設置虛擬目錄或者網站,來實現了這個模擬的動作。

????
?????? 2.實現 IReportServerConnection 接口
????????? 但是如果你的系統中禁止SessionState怎么辦呢。這時你可以考慮實現 IReportServerConnection 或者 IReportServerConnection2 接口:

  1. public ? interface ?IReportServerConnection?:?IReportServerCredentials ??
  2. { ??
  3. ????Uri?ReportServerUrl?{? get ;?} ??
  4. ???? int ?Timeout?{? get ;?} ??
  5. } ??
  6. public ? interface ? class ?IReportServerConnection2?:?IReportServerConnection,?IReportServerCredentials ??
  7. { ??
  8. ????IEnumerable<Cookie>?Cookies?{ get ;} ??
  9. ????IEnumerable< string >?Headers?{ get ;} ??
  10. }??

???????? 從這兩個接口的代碼可以看出,他們的實例可以當做IReportServerCredentials來使用,所以上面介紹的方法對于他們們的實現同樣管用。他們的屬性值同樣默認存儲在SessionState中,當SessionState禁止時,我們要提供其它的訪問方式,以下是我們的實現:
???????

  1. [Serializable] ??
  2. ?? public ? class ?MyReportServerConnection?:?IReportServerConnection2 ??
  3. ??{ ??
  4. ?????? public ?Uri?ReportServerUrl ??
  5. ??????{ ??
  6. ?????????? get ??
  7. ??????????{ ??
  8. ?????????????? string ?url?=?ConfigurationManager.AppSettings[ "MyReportServerUrl" ]; ??
  9. ?????????????? if ?( string .IsNullOrEmpty(url)) ??
  10. ?????????????????? throw ? new ?Exception( "Missing?url?from?the?Web.config?file" ); ??
  11. ?????????????? return ? new ?Uri(url); ??
  12. ??????????} ??
  13. ??????} ??
  14. ?????? public ? int ?Timeout ??
  15. ??????{ ??
  16. ?????????? get ?{? return ?60000;?} ??
  17. ??????} ??
  18. ??
  19. ?????? public ?IEnumerable<Cookie>?Cookies ??
  20. ??????{ ??
  21. ?????????? get ?{? return ? null ;?} ??
  22. ??????} ??
  23. ?????? public ?IEnumerable< string >?Headers ??
  24. ??????{ ??
  25. ?????????? get ?{? return ? null ;?} ??
  26. ??????} ??
  27. ??
  28. ?????? public ?MyReportServerConnection() ??
  29. ??????{ ??
  30. ??????} ??
  31. ??
  32. ??
  33. ?????? public ?WindowsIdentity?ImpersonationUser ??
  34. ??????{ ??
  35. ?????????? get ?{? return ? null ;?} ??
  36. ??????} ??
  37. ??
  38. ?????? public ?ICredentials?NetworkCredentials ??
  39. ??????{ ??
  40. ?????????? get ??
  41. ??????????{ ??
  42. ?????????????? string ?userName?=?ConfigurationManager.AppSettings"[myReportViewerUser]; ??
  43. ?????????????? if ?( string .IsNullOrEmpty(userName)) ??
  44. ?????????????????? throw ? new ?Exception( "Missing?user?name?from?Web.config?file" ); ??
  45. ?????????????? string ?password?=?ConfigurationManager.AppSettings[ "MyReportViewerPassword" ]; ??
  46. ?????????????? if ?( string .IsNullOrEmpty(password)) ??
  47. ?????????????????? throw ? new ?Exception( "Missing?password?from?Web.config?file" ); ??
  48. ?????????????? string ?domain?=?ConfigurationManager.AppSettings[ "MyReportViewerDomain" ]; ??
  49. ?????????????? if ?( string .IsNullOrEmpty(domain)) ??
  50. ?????????????????? throw ? new ?Exception( "Missing?domain?from?Web.config?file" ); ??
  51. ?????????????? return ? new ?NetworkCredential(userName,?password,?domain); ??
  52. ??????????} ??
  53. ??????} ??
  54. ??
  55. ?????? public ? bool ?GetFormsCredentials( out ?Cookie?authCookie, out ? string ?userName, out ? string ?password, out ? string ?authority) ??
  56. ??????{ ??
  57. ??????????authCookie?=? null ; ??
  58. ??????????userName?=? null ; ??
  59. ??????????password?=? null ; ??
  60. ??????????authority?=? null ; ??
  61. ?????????? return ? false ; ??
  62. ??????} ??
  63. ??} ??

???????? 要使HTTP handler在不存儲的情況下還能夠訪問它,必須還要添加 ReportView的WebConfig配置 :

  1. <configuration> ??
  2. ????<appSettings> ??
  3. ????????<add?key= "ReportViewerServerConnection" ?value= "ReportsPortal.MyReportServerConnection,ReportsPortal" /> ??
  4. ????</appSettings> ??
  5. </configuration>??

???????? 同樣的,我們直接賦值給ReportView的屬性,就可以實現報表的“匿名訪問”。
??
  1. this .ReportViewer1.ServerReport.ReportServerCredentials?=?? new ?MyReportServerConnection();??

參考和資源:

???? 1. A Wrapper for Running SQL Server 2008 Reporting Services Reports Anonymously ??? 調用ReportingService2005.asmx服務實現了一個匿名訪問所有報表的管理器。
???? 2. Custom Credentials in the Report Viewer ? 參考資源,有些為這個文章的譯文
???? 3. Anonymous access in SQL RS 2008 ?? 以另外一種方式來實現的匿名訪問

作者: 孤獨俠客 似水流年
出處: http://lonely7345.cnblogs.com/
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。

SQL Server BI Step by Step SSRS 2----SQL Server 2008 Reporting Services實現匿名訪問報表


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲一级毛片在线观播放 | 久热精品免费视频 | 日韩中文字幕精品久久 | 黄色成人在线视频 | 蝌蚪久久 | 俄罗斯老妇性欧美毛茸茸孕交 | 第一色区 | 人.成午夜 | 免费观看成人毛片 | 欧美aaa大片 | 99re国产精品视频首页 | 亚洲国产精品67194成人 | 99精品wwxx在线观看 | 久久国产免费福利资源网站 | 免费综合网 | 日本久久久久亚洲中字幕 | 天天摸天天操免费播放小视频 | 在线观看免费精品国产 | 在线观看自拍视频 | 久久精品国产欧美日韩亚洲 | 亚洲性另类| 国产三级观看久久 | 久久精品免费观看久久 | 国产深夜福利19禁在线播放 | 四虎精品影院2022 | 欧美高清在线精品一区二区不卡 | 日韩一区国产二区欧美三区 | 一级毛片大全免费播放 | 日本高清免费毛片久久看 | 女人的毛片 | 欧美三级一区二区三区 | 高清在线精品一区二区 | 久操伊人| 色视频一区二区三区 | 四虎国产精品永久在线看 | 青青热久久国产久精品秒播 | 波多野野结衣1区二区 | 中文字幕一视频97色伦 | 逼毛片| 久久亚洲精中文字幕冲田杏梨 | 女胁师~牝奴隷调教 |