当前位置: 首页>>代码示例>>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;未经允许,请勿转载。