2017-09-05 70 views
2

我有一個功能,其中檢查和驗證User並在此基礎上的數據顯示給各自的用戶。函數名稱爲Get_AuthenticateUser_Ums(strUserName);網站不工作錯誤,如果功能不起作用

我在Page_load上調用此函數。該功能包含一個web service。現在我想的是隻要服務不工作或有一些問題,我想,該網站不應該被顯示給用戶和信息應及時爲The service is down, so couldnt load the site.

下面是我的代碼

if (!IsPostBack) 
      { 
       Get_AuthenticateUser_Ums(strUserName); } 

而且功能

private void Get_AuthenticateUser_Ums(string strUserName) 
    { 
     try 
     { 
      strReturnMessage = string.Empty; 

      Boolean bolReturn = ObjUMS.AuthenticateApplicationAccess(strUserName, strAppUrl, out strReturnMessage); 

      if (bolReturn) 
      { 
       DataSet dsUserGroups = new DataSet(); 
       dsUserGroups = ObjUMS.GetUserAppDetailsbyUserNameApplicationUrl(strUserName, strAppUrl, out strReturnMessage); 

       if (dsUserGroups.Tables[1] != null && dsUserGroups.Tables[1].Rows.Count > 0) 
       { 
        string strSubGroupName = dsUserGroups.Tables[1].Rows[0]["SUBGROUP_NAME"].ToString(); 

        if (strSubGroupName == "UBR Requester") 
        { 
         if (dsUserGroups.Tables[2] != null && dsUserGroups.Tables[2].Rows.Count > 0) 
         { 
          string[] allStates = dsUserGroups.Tables[2].AsEnumerable().Select(r => r.Field<string>("BOUNDARY_VALUE")).ToArray(); 
          ViewState["States"] = string.Join(",", allStates); 
         } 
        } 
        else 
        { 
         Response.Redirect("~/NotAuthorize.aspx", false); 
        } 
       } 
       else 
       { 
        Response.Redirect("~/NotAuthorize.aspx", false); 
       } 
      } 
      else 
      { 
       Response.Redirect("~/NotAuthorize.aspx", false); 
      } 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 
    } 
+0

什麼不是從這部分工作?你從中得到什麼迴應? –

+0

@sangramparmar:'ObjUMS.AuthenticateApplicationAccess(strUserName,strAppUrl,out strReturnMessage);'如果出現錯誤,則會給出其他明顯的空白信息 – BNN

+0

@VVVV消息將被給出的意思? – Webruster

回答

0

您可以創建一個Method檢查使用url to svc連接,並返回根據您可以看到服務是運行還是不boolean

public bool checkConnection(){ 
var url = "http://nvmbd1bkh150v02/UMSService/UserProvider.svc"; 
bool tosend = false; 
try 
{ 
var myRequest = (HttpWebRequest)WebRequest.Create(url); 

var response = (HttpWebResponse)myRequest.GetResponse(); 

if (response.StatusCode == HttpStatusCode.OK) 
{ 
tosend = true ; 
// it's at least in some way responsive 
// but may be internally broken 
// as you could find out if you called one of the methods for real 
Debug.Write(string.Format("{0} Available", url)); 
} 
else 
{ 
tosend = false; 
// well, at least it returned... 
Debug.Write(string.Format("{0} Returned, but with status: {1}", 
url, response.StatusDescription)); 
} 
} 
catch (Exception ex) 
{ 
// not available at all, for some reason 
Debug.Write(string.Format("{0} unavailable: {1}", url, ex.Message)); 
} 

return tosend; 
}