當前位置: 首頁>>代碼示例>>C#>>正文


C# Uri.Contains方法代碼示例

本文整理匯總了C#中System.Uri.Contains方法的典型用法代碼示例。如果您正苦於以下問題:C# Uri.Contains方法的具體用法?C# Uri.Contains怎麽用?C# Uri.Contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Uri的用法示例。


在下文中一共展示了Uri.Contains方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Specify

        public override void Specify()
        {
            var site = beforeAll(() => IISExpressDriver.StartServer());

            beforeAll(delegate() {
                var hostName = new Uri(site.UrlFor("")).Host;

                expect(() => hostName.Contains("localhost"));

                PSHostsFile.HostsFile.Set(hostName, "127.0.0.1");
            });

            describe("the web application's configuration", delegate()
            {
                var browser = beforeAll(() => new FirefoxDriver());

                it("should have a functioning database connection string", delegate() {

                    browser.Navigate().GoToUrl(site.UrlFor("/Check"));

                    var errorElement = browser.FindElement(BySizzle.CssSelector("#error"));

                    string actual = errorElement.Text.Trim();

                    Assert.That(string.IsNullOrEmpty(actual), "SQL configuration error detected.  Do you have SQL express installed and setup?  If not, you can get it here: http://www.microsoft.com/download/en/details.aspx?id=26729 \nServer reported error:\n\n" + actual);
                });
            });
        }
開發者ID:fschwiet,項目名稱:FBDerp,代碼行數:28,代碼來源:aaa_check_configuration.cs

示例2: BuildHost

 private string BuildHost(string website)
 {
     var host = new Uri(website, UriKind.Absolute).Host;
     if (host.Contains("www."))
     {
         host = host.Substring(4);
     }
     return host;
 }
開發者ID:ncpenn,項目名稱:FindBrokenLinksCommandLine,代碼行數:9,代碼來源:Spider.cs

示例3: get_relative_url_to_app

 private string get_relative_url_to_app()
 {
     var relative_path_when_run_from_command_line = @"..\..\..\";
     var url = new Uri("file:///"+Path.Combine(Environment.CurrentDirectory, relative_path_when_run_from_command_line)).ToString();
     var still_not_up_enough_directories = url.Contains("dotNET-SpecFlow");
     if (still_not_up_enough_directories)
     {
         var relative_path_when_run_from_visual_studio = @"..\..\..\..\";
         url = new Uri("file:///" + Path.Combine(Environment.CurrentDirectory, relative_path_when_run_from_visual_studio)).ToString();
     }
     return url;
 }
開發者ID:quicksolutions,項目名稱:ATDD-Survival-Guide,代碼行數:12,代碼來源:RegistrationPage.cs

示例4: RemoveDuplicateSlashes

 private static string RemoveDuplicateSlashes(string url)
 {
     var path = new Uri(url).AbsolutePath;
     return path.Contains("//") ? url.Replace(path, path.Replace("//", "/")) : url;
 }
開發者ID:rabbal,項目名稱:Mvc5,代碼行數:5,代碼來源:NormalizationUrl.cs

示例5: Request

    /// <summary>
    /// 執行 HttpWebRequest 請求
    /// </summary>
    /// <param name="method">協議方法的類型 WebRequestMethods.Http.XXX</param>
    private static string Request(
      string method,
      string url,
      object parameters = null,
      Encoding encode = null,
      string cookie = null,
      string referer = null,
      string userAgent = null,
      bool? allowAutoRedirect = null,
      string returnHeadersValue = null,
      bool? returnExceptionMessageIfError = null)
    {
      // 驗證 URL
      if (string.IsNullOrEmpty(url) || !Regex.IsMatch(url, @"^https?\:\/\/[^/].+", RegexOptions.IgnoreCase))
      {
        return returnExceptionMessageIfError == true ? "無法識別該 URI 前綴。" : string.Empty;
      }

      try
      {
        url = new Uri(url).ToString(); // 此步會將“http://www.baidu.com”變成“http://www.baidu.com/”

        //// 配置請求

        // 拚接參數
        string ps = joinParameters(parameters);

        if (method == WebRequestMethods.Http.Get && ps.Length > 0)
        {
          url += (url.Contains("?") ? "&" : "?") + ps;
        }

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.Method = method;
        req.Headers.Set("Cache-Control", "no-cache");
        req.Headers.Set("Pragma", "no-cache");

        if (!string.IsNullOrWhiteSpace(cookie)) { req.Headers["Cookie"] = cookie; }
        if (!string.IsNullOrWhiteSpace(referer)) { req.Referer = referer; }
        if (!string.IsNullOrWhiteSpace(userAgent)) { req.UserAgent = userAgent; }
        if (allowAutoRedirect == false) { req.AllowAutoRedirect = false; }

        if (method == WebRequestMethods.Http.Post)
        {
          // !!!寫入 Post 內容必須放在所有設置之後,不然會導致設置 Referer 無效
          req.ContentLength = ps.Length;
          req.ContentType = "application/x-www-form-urlencoded";
          StreamWriter writer = new StreamWriter(req.GetRequestStream());
          writer.Write(ps);
          writer.Close();
        }

        //// 執行請求

        HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

        if (!string.IsNullOrWhiteSpace(returnHeadersValue))
        {
          return resp.Headers[returnHeadersValue];
        }

        Encoding pageEncoding = encode != null ? encode : (string.IsNullOrWhiteSpace(resp.CharacterSet) ? Encoding.UTF8 : Encoding.GetEncoding(resp.CharacterSet));
        Stream receiveStream = resp.GetResponseStream();
        StreamReader readStream = new StreamReader(receiveStream, pageEncoding);
        return readStream.ReadToEnd();
      }
      catch (Exception ex)
      {
        return returnExceptionMessageIfError == true ? ex.Message : string.Empty;
      }
    }
開發者ID:xoyozo,項目名稱:Himiao.Assistant,代碼行數:75,代碼來源:zHttp.cs

示例6: GetAcceptedTypes

		private MimeType[] GetAcceptedTypes(MimeTypes registeredMimes)
		{
			var mimeTypes = new List<MimeType>();
			var originalUrl = Request.Uri.GetLeftPart(UriPartial.Authority) + Request.Url;
			var lastSegment = new Uri(originalUrl).Segments.Last();
			
			if (lastSegment.Contains(".") && (lastSegment.LastIndexOf(".") < lastSegment.Length - 1))
			{
				var extension = lastSegment.Substring(lastSegment.LastIndexOf(".") + 1);
				var mimeType = registeredMimes.GetMimeTypeForExtension(extension);

				if (mimeType != null)
					mimeTypes.Add(mimeType);
			}

			mimeTypes.AddRange(AcceptType.Parse(AcceptHeader, registeredMimes));			
			
			return mimeTypes.Distinct().ToArray();
		}
開發者ID:mgagne-atman,項目名稱:Projects,代碼行數:19,代碼來源:RestfulController.cs

示例7: btnGo_Click

 private void btnGo_Click(object sender, EventArgs args)
 {
     btnGo.Enabled = false;
     miSettings.Enabled = false;
     txtUrl.Enabled = false;
     txtLinks.Clear();
     new Thread(delegate()
     {
         try
         {
             ArrayList<string> includeList = new ArrayList<string>();
             int i = 0;
             foreach (ToolStripMenuItem item in miInclude.DropDownItems)
             {
                 if (item.Checked) { includeList.Add(mRegexList[i]); }
                 i++;
             }
             ArrayList<string> excludeList = new ArrayList<string>();
             i = 0;
             foreach (ToolStripMenuItem item in miExclude.DropDownItems)
             {
                 if (item.Checked) { excludeList.Add(mExcludeList[i]); }
                 i++;
             }
             Set<string> links = new Set<string>();
             Uri baseUrl = new Uri(txtUrl.Text);
             string html = WebUtils.GetWebPageDetectEncoding(txtUrl.Text);
             foreach (string regex in includeList)
             {
                 Regex r = new Regex(regex, RegexOptions.IgnoreCase);
                 Match m = r.Match(html);
                 while (m.Success)
                 {
                     string message = "RSS feed NOT detected.";
                     string url = m.Result("${rssUrl}").Trim();
                     url = new Uri(baseUrl, url).ToString();
                     string urlLower = url.ToLower();
                     // test whether to include link
                     bool ok = true;
                     foreach (string substr in excludeList)
                     {
                         if (urlLower.Contains(substr)) { ok = false; break; }
                     }
                     if (ok && !links.Contains(urlLower))
                     {
                         // test RSS file
                         if (miTestLinks.Checked)
                         {
                             string xml = null;
                             try { xml = WebUtils.GetWebPageDetectEncoding(url); } catch { }
                             bool rssXmlFound = xml != null && TestRssXml(xml);
                             if (rssXmlFound) { message = "RSS feed detected."; }
                             // convert Atom to RSS
                             if (xml != null && miConvertAtomToRss.Checked && !rssXmlFound && TestAtomXml(xml))
                             {
                                 url = "http://www.devtacular.com/utilities/atomtorss/?url=" + HttpUtility.HtmlEncode(url);
                                 xml = null;
                                 try { xml = WebUtils.GetWebPageDetectEncoding(url); }
                                 catch { }
                                 rssXmlFound = xml != null && TestRssXml(xml);
                                 if (rssXmlFound) { message = "RSS feed detected after converting from Atom."; }
                             }
                             else // try the format=xml trick
                             {
                                 if (miFeedburnerFormat.Checked && !rssXmlFound)
                                 {
                                     string newUrl = url + (url.Contains("?") ? "&" : "?") + "format=xml";
                                     try { xml = WebUtils.GetWebPageDetectEncoding(newUrl); } catch { }
                                     rssXmlFound = xml != null && TestRssXml(xml);
                                     if (rssXmlFound)
                                     {
                                         message = "RSS feed detected after applying the format=xml trick.";
                                         url = newUrl;
                                     }
                                 }
                             }
                             if (miRemoveNonRss.Checked && !rssXmlFound) { Invoke(delegate() { txtLinks.Text += "#"; }); }
                             Invoke(delegate() { txtLinks.Text += url + "\r\n"; });
                             if (miOutputTestResult.Checked)
                             {
                                 Invoke(delegate() { txtLinks.Text += "# " + message + "\r\n"; });
                             }
                         }
                         else
                         {
                             Invoke(delegate() { txtLinks.Text += url + "\r\n"; });
                         }
                         links.Add(urlLower);
                     }
                     m = m.NextMatch();
                 } // m.Success
             }
         }
         catch (Exception e)
         {
             TryInvoke(delegate() { txtLinks.Text += e.Message + "\r\n" + e.StackTrace; });
         }
         finally
         {
             TryInvoke(delegate() { btnGo.Enabled = txtUrl.Enabled = miSettings.Enabled = true; });
//.........這裏部分代碼省略.........
開發者ID:project-first,項目名稱:dacqpipe,代碼行數:101,代碼來源:RssScraper.cs


注:本文中的System.Uri.Contains方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。