wuxiren123

          系統集成方案(一).NET集成方案

          NET系統集成有自己獨立的登錄驗證方式。比如,跟報表集成時,不需要再使用報表內置的登錄界面,只需要將報表默認的參數用戶名fr_username和密碼fr_password發送給報表系統,觸發一下報表驗證方式就可以實現單點登錄了,以下用FineReport的.NET跨域單點登錄案例簡單介紹一下。

          系統本身有獨立的登錄驗證方式如下圖:

           

          1.觸發報表驗證方法

          報表集成時不需要再一次進行登錄驗證,只需在項目里面的登錄驗證頁面內觸發一下報表方法,如下js方法:

          function doSubmit() {    
                   
          var username =document.getElementById("username").value;  //此處是用來提取用戶名和密碼
                   var password =document.getElementById("userPwd").value;
                  
          var scr = document.createElement("iframe");      //創建iframe  
                   var dt=new Date();
                  scr.src 
          = "/WebReport/ReportServer?op=fs_load&cmd=sso&username=" + username + "&password=" + password+"&time="+dt.toString();   //將報表驗證用戶名密碼的地址指向此iframe  
                  document.getElementsByTagName("head")[0].appendChild(scr);   //將iframe標簽嵌入到head中  
              }

          注:此處的單點登錄是登錄報表管理平臺,而不是FineReport的數據決策系統,如果需要與數據決策系統做單點登錄,需將

          scr.src = " http://localhost:8075/WebReport/ReportServer?op=fs_load&cmd=sso&username=" + username + "&password=" + password;
          改成
          scr.src 
          = " http://localhost:8075/WebReport/ReportServer?op=fs_load&cmd=sso&username=" + username + "&password=" + password;

          點擊項目里面的登錄按鈕,跳到后臺進行項目里面的驗證,此報表的驗證方式需要在頁面前臺內調用javascript的方式觸發,這邊類似定義了兩個onclick事件,而.net不能同時觸發兩個onclick事件,所以先要觸發完一個onclick事件后再觸發另一個,考慮報表沒有驗證完.net項目就跳轉的話,導致報表沒有驗證成功,所以點擊登錄按鈕首先觸發報表驗證方法,其次再到.net后臺進行驗證。

          3. 觸發.net前臺

          觸發前臺報表驗證方法,新建一個登錄按鈕,設置按鈕OnClientClick屬性為:OnClientClick="doSubmit();return false;",即觸發前臺doSubmit()方法,doSubmit()方法,首先把獲取的用戶名和密碼的值,發送到報表系統,報表服務將帶著這兩個參數訪問認證地址進行認證。而項目本身有個登錄按鈕是觸發的項目后臺的方法,我們這邊首先觸發報表前臺再通過js的方式觸發后臺的那個登錄按鈕,所以這邊需要把之前的登錄按鈕設置隱藏,屬性為Style="display: none;"。

          4. 觸發.net后臺

          報表驗證完再觸發.net項目后臺登錄驗證的方法,通過登錄按鈕ID為Button1,使用document.getElementById("Button1").click();觸發登錄按鈕,但是每個瀏覽器執行的方式不同,所以這邊需要判斷一下,代碼如下:

           if (scr.attachEvent){       //判斷是否為ie瀏覽器  
                         scr.attachEvent("onload"function(){                    //如果為ie瀏覽器則頁面加載完成后立即執行  
                             var f = document.getElementById("Button1");  
                             f.click();  
                         }
          );  
                      }
           else {  
                         scr.onload 
          = function(){              //其他瀏覽器則重新加載onload事件  
                              var f = document.getElementById("Button1");  
                              f.click();  
                         }
          ;  
                   }

          下面以簡單的登錄驗證頁面login.aspx為例head中調用javascript

          示例

          1、登錄前臺頁面

          以簡單的登錄驗證頁面login.aspx為例,head中調用javascript觸發報表方法:

          <%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

          <html xmlns="http://www.w3.org/1999/xhtml" >
          <head runat="server">
              
          <title>無標題頁</title>
            
          <script type="text/javascript" language="javascript">  
                 
          function doSubmit() {    
                   
          var username =document.getElementById("username").value;  //此處是用來提取用戶名和密碼
                   var password =document.getElementById("userPwd").value;
                  
          var scr = document.createElement("iframe");      //創建iframe  
                   var dt=new Date();
                  scr.src 
          = "/WebReport/ReportServer?op=fs_load&cmd=sso&username=" + username + "&password=" + password+"&time="+dt.toString();   //將報表驗證用戶名密碼的地址指向此iframe  
                  if (scr.attachEvent){       //判斷是否為ie瀏覽器  
                         scr.attachEvent("onload"function(){                    //如果為ie瀏覽器則頁面加載完成后立即執行  
                             var f = document.getElementById("Button1");  
                             f.click();  
                         }
          );  
                      }
           else {  
                         scr.onload 
          = function(){              //其他瀏覽器則重新加載onload事件  
                              var f = document.getElementById("Button1");  
                              f.click();  
                         }
          ;  
                   }
            
                  document.getElementsByTagName(
          "head")[0].appendChild(scr);   //將iframe標簽嵌入到head中  
              }
           
            
          </script>
          </head>
          <body>
              
          <form id="form1" runat="server">
              
          <div>
                  
          <asp:TextBox ID="username" runat="server" Style="z-index: 100; left: 156px; position: absolute;
                      top: 42px
          "></asp:TextBox>
                  
          <asp:TextBox ID="userPwd" runat="server" Style="z-index: 101; left: 157px; position: absolute;
                      top: 91px
          "></asp:TextBox>
                  
          <asp:Label ID="Label1" runat="server" Height="22px" Style="z-index: 102; left: 76px;
                      position: absolute; top: 46px
          " Text="用戶名:" Width="77px"></asp:Label>
                  
          <asp:Label ID="Label2" runat="server" Style="z-index: 103; left: 80px; position: absolute;
                      top: 88px
          " Text="密碼:" Width="64px"></asp:Label>
                  
          <asp:Button ID="Button1" runat="server"  Style="z-index: 104; display:none;
                      left: 84px; position: absolute; top: 132px
          " Text="登錄" Width="66px" />
                  
          <asp:Button ID="Button2" runat="server" OnClientClick="doSubmit();return false;"
                      Style
          ="z-index: 106; left: 178px; position: absolute; top: 133px" Text="登錄" Width="100px" />
              
              
          </div>
              
          </form>
          </body>
          </html>

          前臺和后臺驗證成功之后,單點登錄頁面就設計完成了。

          報表工具是通過url傳用戶名和密碼進行驗證,傳到報表服務器是以session的方式保存,防止被人中途攔截會導致系統泄密,可以對登錄進來的密碼進行加密,或者使用https證書,讓請求在傳輸過程中加密,配置方法也很簡單。這種方式還存在一個證書合法性問題,用自己生成的證書,客戶端在訪問報表中瀏覽器會顯示證書非法警告,所以需要去購買合法證書。目前國內最便宜的證書一年是一千多元。

          2、平臺設置

          一般情況下報表集成到.net系統,首先登錄訪問.net的項目,所以自定義登錄頁面訪問地址可以不需要設置,如果沒有登錄到.ne項目,先訪問我們的報表了,而這時訪問報表的登錄頁面是報表內置的登錄界面,需使用自動登錄頁面地址為您系統的登錄地址,操作如下:

          打開http://localhost/WebReport/ReportServer?op=fr_platform,FR管理平臺,選擇權限配置>登錄設置,自定義登錄頁面訪問地址上,輸入自己的登錄頁面路徑http://localhost/FRtest/login.aspx,如下圖所示:





          posted on 2016-07-27 10:27 喝水居然長肉 閱讀(100) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 额尔古纳市| 巴林左旗| 天镇县| 柘荣县| 明溪县| 洪洞县| 金川县| 衡阳县| 和政县| 遵义市| 兰坪| 定南县| 涟源市| 共和县| 历史| 凤山市| 抚顺县| 龙井市| 马鞍山市| 镇平县| 东平县| 固原市| 循化| 贵港市| 宾阳县| 万源市| 措勤县| 奉新县| 新民市| 富蕴县| 黔西县| 平遥县| 府谷县| 云和县| 岐山县| 轮台县| 临湘市| 陇南市| 鄂伦春自治旗| 张北县| 调兵山市|