• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# UrlBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中UrlBuilder的典型用法代码示例。如果您正苦于以下问题:C# UrlBuilder类的具体用法?C# UrlBuilder怎么用?C# UrlBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UrlBuilder类属于命名空间,在下文中一共展示了UrlBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetFriendlyURL

        public static string GetFriendlyURL(PageData pageData)
        {
            UrlBuilder pageURLBuilder = new UrlBuilder(pageData.LinkURL);
            EPiServer.Global.UrlRewriteProvider.ConvertToExternal(pageURLBuilder, pageData.PageLink, UTF8Encoding.UTF8);

            return GetSiteRoot() + pageURLBuilder.Path;
        }
开发者ID:sandeepnp,项目名称:PugPigConnector,代码行数:7,代码来源:Common.cs


示例2: GetExternalUrl

        /// <summary>
        /// Adds scheme and host to a relative url.
        /// </summary>
        /// <param name="input">Url</param>
        /// <returns>String</returns>
        public static string GetExternalUrl(this string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return string.Empty;
            }

            var siteUri = HttpContext.Current != null
                            ? HttpContext.Current.Request.Url
                            : SiteDefinition.Current.SiteUrl;

            if (!input.StartsWith("/"))
            {
                input = "/" + input;
            }

            var urlBuilder = new UrlBuilder(input)
            {
                Scheme = siteUri.Scheme,
                Host = siteUri.Host,
                Port = siteUri.Port
            };

            return urlBuilder.ToString();
        }
开发者ID:dnasir,项目名称:EPi.Extensions,代码行数:30,代码来源:StringExtensions.cs


示例3: GetNewUrl

        public string GetNewUrl(string oldUrl)
        {
            if(!oldUrl.EndsWith("/"))
            {
                oldUrl += "/";
            }

            // lookup Url in DDS
            var store = typeof(UrlRemapEntity).GetStore();
            var foundItem = store.Items<UrlRemapEntity>().FirstOrDefault(i => i.OldUrl.Equals(oldUrl));

            if(foundItem != null)
            {
                var reference = new PageReference(foundItem.PageId);
                var pageData = DataFactory.Instance.GetPage(reference);
                pageData = pageData.GetPageLanguage(foundItem.LanguageBranch);
                var builder = new UrlBuilder(UriSupport.AddLanguageSelection(pageData.LinkURL, pageData.LanguageBranch));

                if(Global.UrlRewriteProvider.ConvertToExternal(builder, pageData.PageLink, Encoding.UTF8))
                {
                    return builder.Uri.ToString();
                }
            }

            return null;
        }
开发者ID:ajuris,项目名称:opensource,代码行数:26,代码来源:OldNewUrlMapper.cs


示例4: ToSitemapEntry

        public static SitemapEntry ToSitemapEntry(this PageData page, LanguageSelector language, string bundle)
        {
            if (page == null)
            {
                return SitemapEntry.Empty;
            }

            var urlRewriter = ServiceLocator.Current.GetInstance<IUrlRewriteProviderWrapper>();
            var hostBindingsService = ServiceLocator.Current.GetInstance<IHostBindingsService>();

            Uri baseUri;
            baseUri = hostBindingsService.AllBindings().TryGetValue(language.LanguageBranch, out baseUri) ?
                            baseUri :
                            hostBindingsService.DefaultHost();
            var location = new UrlBuilder(new Uri(baseUri, page.LinkURL.ToLower()));
            urlRewriter.GetFriendlyUrl(location, null, Encoding.UTF8);

            return new SitemapEntry
            {
                IsEmpty = false,
                Location = location.Uri,
                LastModified = page.Changed,
                ChangeFrequency = Frequency.Weekly,
                Priority = 0.5F,
                Language = language.LanguageBranch,
                Bundle = !string.IsNullOrWhiteSpace(bundle) ? bundle : Constants.Bundles.Default
            };
        }
开发者ID:kirolosgerges,项目名称:Blog,代码行数:28,代码来源:PageDataExtentions.cs


示例5: XForm_AfterSubmitPostedData

        /// <summary>
        /// Handles the AfterSubmitPostedData event of the XFormControl.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EPiServer.XForms.WebControls.SaveFormDataEventArgs"/> instance containing the event data.</param>
        public void XForm_AfterSubmitPostedData(object sender, SaveFormDataEventArgs e)
        {
            XFormControl control = (XFormControl)sender;

            if (control.FormDefinition.PageGuidAfterPost != Guid.Empty)
            {
                PermanentContentLinkMap pageMap = PermanentLinkMapStore.Find(control.FormDefinition.PageGuidAfterPost) as PermanentContentLinkMap;
                if (pageMap != null)
                {
                    string internalUrl = pageMap.MappedUrl.ToString();
                    internalUrl = UriSupport.AddLanguageSelection(internalUrl, ContentLanguage.PreferredCulture.Name);
                    UrlBuilder urlBuilder = new UrlBuilder(internalUrl);
                    //Rewrite the url to make sure that it gets the friendly url if such a provider has been configured.
                    Global.UrlRewriteProvider.ConvertToExternal(urlBuilder, null, Encoding.UTF8);

                    //Always cast UrlBuilders to get a correctly encoded url since ToString() is for "human" readability.
                    control.Page.Response.Redirect((string)urlBuilder);
                    return;
                }
            }

            //After the form has been posted we remove the form elements and add a "thank you message".
            control.Controls.Clear();
            Label label = new Label();
            label.CssClass = "thankyoumessage";
            label.Text = LocalizationService.Current.GetString("/form/postedmessage");
            control.Controls.Add(label);
        }
开发者ID:kmorcinek,项目名称:EPiServer7-alloy-template-web-forms,代码行数:33,代码来源:Global.asax.cs


示例6: ConvertUrlToExternal

        public string ConvertUrlToExternal(PageData pageData = null, PageReference p = null)
        {
            if (pageData == null && p == null)
            {
                return string.Empty;
            }
            var page = pageData ?? _repository.Get<PageData>(p);

            var pageUrlBuilder = new UrlBuilder(page.LinkURL);

            Global.UrlRewriteProvider.ConvertToExternal(pageUrlBuilder, page.PageLink, Encoding.UTF8);

            string pageURL = pageUrlBuilder.ToString();

            UriBuilder uriBuilder = new UriBuilder(SiteDefinition.Current.SiteUrl);

            uriBuilder.Path = pageURL;
            var jj = ServiceLocator.Current.GetInstance<UrlResolver>().GetUrl(p);
            if (uriBuilder.Path == "/")
                return uriBuilder.Uri.AbsoluteUri;

            string[] words = uriBuilder.Uri.AbsoluteUri.Split(new char[] {':', '/', '.'},
                        StringSplitOptions.RemoveEmptyEntries);
            bool reoccurs = words.Count(q => q == "http") > 1;

            if (reoccurs)
                return uriBuilder.Uri.LocalPath.StartsWith("/") ? uriBuilder.Uri.LocalPath.Remove(0,1) : uriBuilder.Uri.LocalPath;

            return uriBuilder.Uri.AbsoluteUri;
        }
开发者ID:EpiCenterADC,项目名称:EPICenter,代码行数:30,代码来源:PageService.cs


示例7: Serialize

        /// <summary>
        /// Serialize to XElement
        /// </summary>
        /// <returns></returns>
        public override XElement Serialize(XNamespace namespaceXForms)
        {
            var builder = new UrlBuilder(GetFormAction());
            if (this.RecipientEmailAddress != null)
            {
                builder.QueryCollection.Add("to", this.RecipientEmailAddress);
            }
            if (this.SenderEmailAddress != null)
            {
                builder.QueryCollection.Add("from", this.SenderEmailAddress);
            }
            if (this.EmailSubject != null)
            {
                builder.QueryCollection.Add("subject", this.EmailSubject);
            }

            var formElement = new XElement(namespaceXForms + "submit",
                    new XAttribute("action", builder.ToString()),
                    new XAttribute("method", string.Empty),
                    new XAttribute("name", "ctl00$FullRegion$FormControl$ctl11"));

            var formLabelElement = new XElement(namespaceXForms + "label", this.ButtonText);
            formElement.Add(formLabelElement);

            return formElement;
        }
开发者ID:alfnilsson,项目名称:EPiServerStronglyTypedXForms,代码行数:30,代码来源:SubmitButtonFormFieldModel.cs


示例8: OnLoad

        protected override void OnLoad(EventArgs e)
        {
            // We don't want to modify EPiServer's code if it's not a PostBack.
            if (!Page.IsPostBack)
            {
                base.OnLoad(e);
                return;
            }

            var linkinternalurl = Control.FindControlRecursive<InputPageReference>("linkinternalurl");
            var linklanguages = Control.FindControlRecursive<DropDownList>("linklanguages");
            var activeTab = Control.FindControlRecursive<HtmlInputHidden>("activeTab");
            var linktypeinternal = Control.FindControlRecursive<HtmlInputRadioButton>("linktypeinternal");

            var request = HttpContext.Current.Request;

            // Modified parts of EPiServer's HyperlinkProperties.aspx.cs load method below
            var function = "function CloseAfterPostback(e) {";
            if (String.CompareOrdinal(activeTab.Value, "0") == 0 && linktypeinternal.Checked)
            {
                var urlBuilder = new UrlBuilder(DataFactory.Instance.GetPage(linkinternalurl.PageLink).StaticLinkURL);
                var linkLang = request.Form[linklanguages.UniqueID];
                if (!string.IsNullOrEmpty(linkLang))
                {
                    urlBuilder.QueryCollection["epslanguage"] = linkLang;
                }
                var ddlSelectedBookmark = request["ddlBookmarkSelector"];
                var bookmarkOrDefault = !BookmarkLocator.DefaultBookmark.Equals(ddlSelectedBookmark) ? string.Concat("#", ddlSelectedBookmark) : string.Empty;
                function = function + "EPi.GetDialog().returnValue.href = '" + urlBuilder + bookmarkOrDefault + "';";
            }
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "closeafterpostback", function + "EPi.GetDialog().Close(EPi.GetDialog().returnValue);}", true);
            ((PageBase)Page).ScriptManager.AddEventListener(Page, new CustomEvent(EventType.Load, "CloseAfterPostback"));
        }
开发者ID:kirolosgerges,项目名称:Blog,代码行数:33,代码来源:HyperlinkPropertiesAdapter.cs


示例9: PreProcess

        private string PreProcess(XhtmlString xhtmlString)
        {
            // The store value of an XhtmlString contains placeholder content for certain dynamic content.  We want to
            // pre-load this data to before we send it off to the app.  In order to load personalized content, dynamic controls, etc.,
            // we use the following methods to get the "rendered results" of the XhtmlString property
            var htmlHelper = Helpers.MvcHelper.GetHtmlHelper();
            string mvcHtmlResults = EPiServer.Web.Mvc.Html.XhtmlStringExtensions.XhtmlString(htmlHelper, xhtmlString).ToHtmlString();

            // replace image URLs with a full URL path
            string workingResults = Regex.Replace(mvcHtmlResults, "<img(.+?)src=[\"\']/(.+?)[\"\'](.+?)>", "<img $1 src=\"http://ascend-dev.adagetechnologies.com/$2\" $3>");

            // find all internal href items
            var regexMatches = Regex.Matches(mvcHtmlResults, "href=[\"\'](.*?)[\"\']");
            var resolver = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<UrlResolver>();

            // for each item attempt to determine if they are an internal page link
            foreach(Match eachUrlMatch in regexMatches)
            {
                UrlBuilder eachUrl = new UrlBuilder(eachUrlMatch.Groups[1].Value);
                var currentRoute = resolver.Route(eachUrl);
                if (currentRoute != null)
                {
                    string internalContentLink = string.Format("href=\"index.html#/app/content/{0}\"", currentRoute.ContentLink.ID);
                    workingResults = workingResults.Replace(eachUrlMatch.Value, internalContentLink);
                }
            }

            return workingResults;
        }
开发者ID:adagetech,项目名称:EPiServer-Cordova-Demo,代码行数:29,代码来源:MobilePageDataController.cs


示例10: GetKey

 /// <summary>Retrieves an individual key from the gamer properties.</summary>
 /// <returns>Promise resolved when the operation has completed. The attached bundle contains the fetched property.
 ///     As usual with bundles, it can be casted to the proper type you are expecting.
 ///     In case the call fails, the bundle is not attached, the call is marked as failed with a 404 status.</returns>
 /// <param name="key">The name of the key to be fetched.</param>
 public Promise<Bundle> GetKey(string key)
 {
     UrlBuilder url = new UrlBuilder("/v2.6/gamer/property").Path(domain).Path(key);
     HttpRequest req = Gamer.MakeHttpRequest(url);
     return Common.RunInTask<Bundle>(req, (response, task) => {
         task.PostResult(response.BodyJson["properties"]);
     });
 }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:13,代码来源:GamerProperties.cs


示例11: GetKey

 /// <summary>Retrieves an individual key from the key/value system.</summary>
 /// <returns>Promise resolved when the operation has completed. The attached bundle contains the fetched property.
 ///     As usual with bundles, it can be casted to the proper type you are expecting.
 ///     If the property doesn't exist, the call is marked as failed with a 404 status.</returns>
 /// <param name="key">The name of the key to be fetched.</param>
 public Promise<Bundle> GetKey(string key)
 {
     UrlBuilder url = new UrlBuilder("/v1/vfs").Path(domain).Path(key);
     HttpRequest req = Cloud.MakeUnauthenticatedHttpRequest(url);
     return Common.RunInTask<Bundle>(req, (response, task) => {
         task.PostResult(response.BodyJson);
     });
 }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:13,代码来源:GameVfs.cs


示例12: Balance

 /// <summary>
 /// Retrieves the balance of the user. That is, the amount of "items" remaining after the various executed
 /// transactions.
 /// </summary>
 /// <returns>Promise resolved when the operation has completed. The attached bundle contains the balance.
 ///     You can query the individual items by doing `result.Value["gold"]` for instance.</returns>
 public Promise<Bundle> Balance()
 {
     UrlBuilder url = new UrlBuilder("/v1/gamer/tx").Path(domain).Path("balance");
     HttpRequest req = Gamer.MakeHttpRequest(url);
     return Common.RunInTask<Bundle>(req, (response, task) => {
         task.PostResult(response.BodyJson);
     });
 }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:14,代码来源:GamerTransactions.cs


示例13: Given_Empty_Parameter_Correct_Url_Is_Generated

        public void Given_Empty_Parameter_Correct_Url_Is_Generated()
        {
            var url = new UrlBuilder(BaseUrl)
                            .WithParameter("limit", null)
                            .Build();

            Assert.AreEqual("http://api.dotnetgroup.dev/", url);
        }
开发者ID:mmozuras,项目名称:DotNetGroup,代码行数:8,代码来源:UrlBuilderTests.cs


示例14: Run

 /// <summary>Runs a batch on the server, authenticated as a gamer (gamer-scoped).</summary>
 /// <returns>Promise resolved when the operation has completed. The attached bundle is the JSON data returned
 ///     by the batch.</returns>
 /// <param name="batchName">Name of the batch to run, as configured on the server.</param>
 /// <param name="batchParams">Parameters to be passed to the batch.</param>
 public Promise<Bundle> Run(string batchName, Bundle batchParams = null)
 {
     UrlBuilder url = new UrlBuilder("/v1/gamer/batch").Path(domain).Path(batchName);
     HttpRequest req = Gamer.MakeHttpRequest(url);
     req.BodyJson = batchParams ?? Bundle.Empty;
     return Common.RunInTask<Bundle>(req, (response, task) => {
         task.PostResult(response.BodyJson);
     });
 }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:14,代码来源:GamerBatches.cs


示例15: RemoveKey

 /// <summary>Removes a single key from the user properties.</summary>
 /// <returns>Promise resolved when the operation has completed.</returns>
 /// <param name="key">The name of the key to remove.</param>
 public Promise<Done> RemoveKey(string key)
 {
     UrlBuilder url = new UrlBuilder("/v2.6/gamer/property").Path(domain).Path(key);
     HttpRequest req = Gamer.MakeHttpRequest(url);
     req.Method = "DELETE";
     return Common.RunInTask<Done>(req, (response, task) => {
         task.PostResult(new Done(response.BodyJson));
     });
 }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:12,代码来源:GamerProperties.cs


示例16: Given_Several_Parts_Correct_Url_Is_Generated

        public void Given_Several_Parts_Correct_Url_Is_Generated()
        {
            var url = new UrlBuilder(BaseUrl)
                            .WithPart("get")
                            .WithPart(1)
                            .Build();

            Assert.AreEqual("http://api.dotnetgroup.dev/get/1", url);
        }
开发者ID:mmozuras,项目名称:DotNetGroup,代码行数:9,代码来源:UrlBuilderTests.cs


示例17: Given_Date_From_And_Limit_Parameter_Correct_Url_Is_Generated

        public void Given_Date_From_And_Limit_Parameter_Correct_Url_Is_Generated()
        {
            var url = new UrlBuilder(BaseUrl)
                            .WithParameter("from", "2012-01-01 10:00:00")
                            .WithParameter("limit", 10)
                            .Build();

            Assert.AreEqual("http://api.dotnetgroup.dev/?from=2012-01-01%2010:00:00&limit=10", url);
        }
开发者ID:mmozuras,项目名称:DotNetGroup,代码行数:9,代码来源:UrlBuilderTests.cs


示例18: DismissInvitation

 /// <summary>Dismisses a pending invitation for the current user and the match. Fails if the user has not been invited.</summary>
 /// <returns>Promise resolved when the operation has completed.</returns>
 public Promise<Done> DismissInvitation()
 {
     UrlBuilder url = new UrlBuilder("/v1/gamer/matches").Path(MatchId).Path("invitation");
     HttpRequest req = Gamer.MakeHttpRequest(url);
     req.Method = "DELETE";
     return Common.RunInTask<Done>(req, (response, task) => {
         task.PostResult(new Done(true, response.BodyJson));
     });
 }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:11,代码来源:MatchInfo.cs


示例19: GetItem

        public Item GetItem(string objectId)
        {
            var url = new UrlBuilder(this.baseUrl)
                .WithPart("get")
                .WithPart(objectId)
                .Build();

            return this.jsonClient.Get<Item>(url);
        }
开发者ID:mmozuras,项目名称:DotNetGroup,代码行数:9,代码来源:StreamService.cs


示例20: CleanNestedCollections

        private static void CleanNestedCollections(UrlBuilder current)
        {
            var facetQuery = current.QueryList[StorefrontConstants.QueryStrings.Facets];

            if (facetQuery != null)
            {
                var decodedFacets = HttpUtility.UrlDecode(facetQuery);
                current.QueryList.AddOrSet(StorefrontConstants.QueryStrings.Facets, decodedFacets);
            }
        }
开发者ID:Brad-Christie,项目名称:sccs-demo,代码行数:10,代码来源:UrlExtensionMethods.cs



注:本文中的UrlBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UrlHelper类代码示例发布时间:2022-05-24
下一篇:
C# Url类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap