检测某个Url是否可以访问

 
public   partial   class  _Default : System.Web.UI.Page  
{  
    
string accountGUID = "";  
    
protected void Page_Load(object sender, EventArgs e)  
    
{  
        
string entityId = Request.QueryString["oId"];  
        Guid accountId 
= (entityId == null? (new Guid("00000000-0000-0000-0000-000000000000")) : new Guid(entityId);  
        accountGUID 
= accountId.ToString();  
        
string url = "http://WSS:6666/PL/" + accountGUID; // PL is a picture library in WSS 3.0  
  
        
if (CheckUrl(url))  
        
{  
            Response.Redirect(url);  
        }
  
        
else  
        
{  
            Label1.Text 
= "This account doesn't has a Pictures Library, please create a one for it.";  
        }
  
    }
  
  
    
public static bool CheckUrl(string url)  
    
{  
        
//check if the url(pictures library) is existing  
        HttpWebResponse httpResponse = null;  
  
        
try  
        
{  
            HttpWebRequest httpRequest 
= (HttpWebRequest)WebRequest.Create(url);  
            httpRequest.Credentials 
= System.Net.CredentialCache.DefaultCredentials;  
            httpResponse 
= (HttpWebResponse)httpRequest.GetResponse();  
            
return (httpResponse.StatusCode == System.Net.HttpStatusCode.OK);  
        }
  
        
catch (Exception ex)  
        
{  
            
return false;  
        }
  
    }
  
  
    
protected void Button1_Click(object sender, EventArgs e)  
    
{  
        
//Response.Redirect("http://WSS:6666/PL/Forms/Upload.aspx?Type=1");  
        SPSite Site = new SPSite("http://WSS:6666"); //site url  
        SPWeb Web = Site.OpenWeb();  
        Site.AllowUnsafeUpdates 
= true;  
        Web.AllowUnsafeUpdates 
= true;  
        SPFolder rootFolder 
= Web.GetFolder("PL"); // PL is a picture library in WSS 3.0  
        rootFolder.SubFolders.Add(accountGUID);  
        Page_Load(
nullnull);  
    }
  
}
  

上面的那个方法 效率太低。如果知道了数据类型 就直接省去了判定 直接转化
   /// <summary>
        
/// 合同 状换类
        
/// </summary>
        
/// <param name="info"></param>
        
/// <returns></returns>

         public   static  contract GetContractInstance(ContractInfo info)
        
{
            contract value 
= new contract();
       
            
if (info.AllotmentType != 0)
            
{
                value.allotmenttypecode 
= info.AllotmentType;
            }


            
if (info.BillingCustomerID != System.Guid.Empty && info.BillingCustomerID!=null)
            
{
               value.billingcustomerid 
= new Customer();
               value.billingcustomerid.type 
= EntityName.account.ToString();
               value.billingcustomerid.Value 
= new Guid(info.BillingCustomerID.ToString());
            }


            
if (info.ContractID != System.Guid.Empty && info.ContractID!=null)
            
{
                value.contractid 
= info.ContractID;
            }

            
if (info.ActiveDate != "")
            
{
                value.activeon 
= CrmTypes.CreateCrmDateTime(info.ActiveDate);
            }

            
if (info.ExpiresDate != "")
            
{
                value.expireson 
= CrmTypes.CreateCrmDateTime(info.ExpiresDate);
            }

            
if (info.BillingStartDate != "")
            
{
                value.billingstarton 
= CrmTypes.CreateCrmDateTime(info.BillingStartDate);
            }

            
if (info.BillingEndDate != "")
            
{
                value.billingendon 
= CrmTypes.CreateCrmDateTime(info.BillingEndDate);
            }

            
if (info.BillingFrequency != 0)
            
{
                value.billingfrequencycode 
= info.BillingFrequency;
            }

            
if (info.BilltoAddress!=null && info.BilltoAddress != System.Guid.Empty)
            
{
                value.billtoaddress 
= info.BilltoAddress;
            }

            value.contractlanguage 
= info.ContractLanguage;

            
if (info.ContractServiceLevel != 0)
            
{
                value.contractservicelevelcode 
= info.ContractServiceLevel;
            }

            
if (info.ContractTemplateID != System.Guid.Empty && info.ContractTemplateID!=null)
            
{
                value.contracttemplateid 
= info.ContractTemplateID;
            }

            
if ((int)info.ContractKind != 0)
            
{
                value.mls_contracttype 
= (int)info.ContractKind;
            }


            
if (info.CustomerID != System.Guid.Empty && info.CustomerID!=null)
            
{
                value.customerid 
= new Customer();
                value.customerid.type 
= EntityName.account.ToString();
                value.customerid.Value 
= new Guid(info.CustomerID.ToString());
            }

           
            value.mls_cmmnamt 
= info.CommissionAmount;
            
// 佣金抽取基于方式
            if ((int)info.CommissionBasedOnType != 0)
            
{
                value.mls_cmmnbasedon 
= (int)info.CommissionBasedOnType;
            }


            value.mls_cmmnextprog 
= info.ExternalProgram;
            value.mls_cmmnmacro 
= info.MacroExpression;
            value.mls_cmmnmax 
= info.CommissionMax;
            
// 佣金提取方法类型
            if ((int)info.CommissionMethodType != 0)
            
{
                value.mls_cmmnmethod 
= (int)info.CommissionMethodType;
            }

            value.mls_cmmnmin 
= info.CommissionMin;
            value.mls_cmmnpct 
= info.CommissionPercent;

            
if (info.ServiceAddress!=null && info.ServiceAddress != System.Guid.Empty)
            
{
                value.serviceaddress 
= info.ServiceAddress;
            }


            
if (info.OriginatingContract != null && info.OriginatingContract != System.Guid.Empty)
            
{
                value.originatingcontract 
= info.OriginatingContract;
            }

            value.title 
= info.Title;
            value.usediscountaspercentage 
= info.UseDiscountAsPercentage;
            
if ((int)info.Status != 0)
            
{
                value.statuscode 
= (int)info.Status;
            }


            
return value;
        }


        
/// <summary>
        
/// 合同 状换类
        
/// </summary>
        
/// <param name="value"></param>
        
/// <returns></returns>

         public   static  ContractInfo GetContractInfoInstance(contract value)
        
{
            ContractInfo info 
= new ContractInfo();

            
if (value.contractid != null)
            
{
                info.ContractID 
= value.contractid.GetValue();
            }


            info.Title 
= value.title;
            
if (value.allotmenttypecode != null)
            
{
                info.AllotmentType 
= value.allotmenttypecode.GetValue();
            }

            info.ContractNumber 
= value.contractnumber;
            info.ContractLanguage 
= value.contractlanguage;
            
if (value.contracttemplateid != null)
            
{
                info.ContractTemplateID 
= value.contracttemplateid.GetValue();
            }

            
if (value.customerid != null)
            
{
                info.CustomerID 
= value.customerid.GetValue();
            }

            info.ContractLanguage 
= value.contractlanguage;
            
if (value.contractservicelevelcode != null)
            
{
                info.ContractServiceLevel 
= value.contractservicelevelcode.GetValue();
            }

            info.ContractTemplateAbbreviation 
= value.contracttemplateabbreviation;
            
if (value.contracttemplateid != null)
            
{
                info.ContractTemplateID 
= value.contracttemplateid.GetValue();
            }

            
if (value.mls_contracttype != null)
            
{
                info.ContractKind 
= (ContractType)value.mls_contracttype.GetValue();
            }

            
if ((Object)value.netprice != null)
            
{
                info.NetPrice 
= value.netprice.GetValue();
            }

            
if ((Object)value.totaldiscount != null)
            
{
                info.TotalDiscount 
= value.totaldiscount.GetValue();
            }

            
if ((Object)value.totalprice != null)
            
{
                info.TotalPrice 
= value.totalprice.GetValue();
            }

            
if (value.usediscountaspercentage != null)
            
{
                info.UseDiscountAsPercentage 
= value.usediscountaspercentage.GetValue();
            }

            
if (value.billingcustomerid != null)
            
{
                info.BillingCustomerID 
= value.billingcustomerid.GetValue();
            }

            
if (value.billingfrequencycode != null)
            
{
                info.BillingFrequency 
= value.billingfrequencycode.GetValue();
            }

            
if (value.billingendon != null)
            
{
                info.BillingEndDate 
= value.billingendon.Value;
            }

            
if (value.billingstarton != null)
            
{
                info.BillingStartDate 
= value.billingstarton.Value;
            }

            
if (value.billtoaddress != null)
            
{
                info.BilltoAddress 
= value.billtoaddress.GetValue();
            }

            
// 原始合同
            if (value.originatingcontract != null)
            
{
                info.OriginatingContract 
= value.originatingcontract.GetValue();
            }

            
if (value.serviceaddress!=null)
            
{
                info.ServiceAddress 
= value.serviceaddress.GetValue();
            }

            
// 合同状态
            if (value.statuscode != null)
            
{
                info.Status 
= (ContractStatus)value.statuscode.GetValue();
            }

            
if (value.createdby != null)
            
{
                info.CreatedBy 
= value.createdby.GetValue();
            }

            
if (value.createdon != null)
            
{
                info.CreatedDate 
= value.createdon.Value;
            }

            
if (value.activeon != null)
            
{
                info.ActiveDate 
= value.activeon.Value;
            }

            
if (value.modifiedby != null)
            
{
                info.ModifiedBy 
= value.modifiedby.GetValue();
            }

            
if (value.modifiedon != null)
            
{
                info.ModifiedDate 
= value.modifiedon.Value;
            }

            
if (value.cancelon != null)
            
{
                info.CancelDate 
= value.cancelon.Value;
            }

            
if (value.duration != null)
            
{
                info.Duration 
= value.duration.GetValue();
            }

            info.EffectivityCalendar 
= value.effectivitycalendar;
            
if (value.expireson != null)
            
{
                info.ExpiresDate 
= value.expireson.Value;
            }


            
if ((Object)value.mls_cmmnamt != null)
            
{
                info.CommissionAmount 
= value.mls_cmmnamt.GetValue();
            }

            
if ((Object)value.mls_cmmnmin != null)
            
{
                info.CommissionMin 
= value.mls_cmmnmin.GetValue();
            }

            
if ((Object)value.mls_cmmnmax != null)
            
{
                info.CommissionMax 
= value.mls_cmmnmax.GetValue();
            }

            
if (value.mls_cmmnbasedon != null)
            
{
                info.CommissionBasedOnType 
= (CommisionBaseOn)value.mls_cmmnbasedon.GetValue();
            }

            info.ExternalProgram 
= value.mls_cmmnextprog;
            info.MacroExpression 
= value.mls_cmmnmacro;
            
// 佣金提取方式类型
            if (value.mls_cmmnmethod != null)
            
{
                info.CommissionMethodType 
= (CommisionMethod)value.mls_cmmnmethod.GetValue();
            }

            
if (value.mls_cmmnpct != null)
            
{
                info.CommissionPercent 
= value.mls_cmmnpct.GetValue();
            }
 
            
return info;
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值