zoukankan      html  css  js  c++  java
  • Asp.net验证网络文件地址是否有效的方法

     1 public static bool CheckFileURLValidity(string URL)
     2 {
     3             bool IsValid = false;
     4 
     5             if (URL.Trim() != "" && URL.Trim().Contains("."))
     6             {
     7                 try
     8                 {
     9                     Uri uri = new Uri(URL);
    10                     HttpWebRequest webRequest = HttpWebRequest.Create(uri) as HttpWebRequest;
    11                     webRequest.Method = "HEAD";
    12 
    13                     HttpWebResponse webResponse = webRequest.GetResponse() as HttpWebResponse;
    14                     if (webResponse.StatusCode == HttpStatusCode.OK)
    15                     {
    16                         IsValid = true;
    17                     }
    18                 }
    19                 catch (WebException ex)
    20                 {
    21                     try
    22                     {
    23                         IsValid = ((ex.Response as HttpWebResponse).StatusCode != HttpStatusCode.NotFound);
    24                     }
    25                     catch
    26                     {
    27                         IsValid = (ex.Status == WebExceptionStatus.Success);
    28                     }
    29                 }
    30                 catch (Exception ex)
    31                 {
    32 
    33                 }
    34             }
    35 
    36             return IsValid;
    37 }

    原文出处

       

  • 相关阅读:
    SQL注入的一般步骤及防范方法
    防止SQL注入的五种方法
    document.getElementById("orderform").submit() 提交给了谁?
    页面调试-F12
    rs.last()续
    rs.last()
    14课后习题
    HashMap
    链表
    习题
  • 原文地址:https://www.cnblogs.com/61007257Steven/p/10609350.html
Copyright © 2011-2022 走看看