本文整理汇总了C#中UrlBuilder类的典型用法代码示例。如果您正苦于以下问题:C# UrlBuilder类的具体用法?C# UrlBuilder怎么用?C# UrlBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UrlBuilder类属于命名空间,在下文中一共展示了UrlBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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();
}
示例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;
}
示例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
};
}
示例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);
}
示例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;
}
示例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;
}
示例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"));
}
示例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;
}
示例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"]);
});
}
示例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);
});
}
示例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);
});
}
示例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);
}
示例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);
});
}
示例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));
});
}