本文整理汇总了C#中System.Url类的典型用法代码示例。如果您正苦于以下问题:C# Url类的具体用法?C# Url怎么用?C# Url使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Url类属于System命名空间,在下文中一共展示了Url类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: action_Click
protected void action_Click(object sender, EventArgs e)
{
string url = input.Text;
if (string.IsNullOrEmpty(url))
{
return;
}
// Execute methods on the UrlShortener service based upon the type of the URL provided.
try
{
string resultURL;
if (IsShortUrl(url))
{
// Expand the URL by using a Url.Get(..) request.
Url result = service.Url.Get(url).Execute();
resultURL = result.LongUrl;
}
else
{
// Shorten the URL by inserting a new Url.
Url toInsert = new Url { LongUrl = url };
toInsert = service.Url.Insert(toInsert).Execute();
resultURL = toInsert.Id;
}
output.Text = string.Format("<a href=\"{0}\">{0}</a>", resultURL);
}
catch (GoogleApiException ex)
{
var str = ex.ToString();
str = str.Replace(Environment.NewLine, Environment.NewLine + "<br/>");
str = str.Replace(" ", " ");
output.Text = string.Format("<font color=\"red\">{0}</font>", str);
}
}
示例2: VirtualFileStore
public VirtualFileStore(string virtualPathProviderName)
{
if (string.IsNullOrEmpty(virtualPathProviderName))
{
throw new ArgumentNullException("virtualPathProviderName");
}
var vppRegistrationHandler = ServiceLocator.Current.GetInstance<VirtualPathRegistrationHandler>();
var storeVirtualPathProviderSettings = vppRegistrationHandler.RegisteredVirtualPathProviders.Values.FirstOrDefault(ps => ps.Name == virtualPathProviderName);
if (storeVirtualPathProviderSettings == null)
{
throw new ArgumentException(string.Format("Virtual path provider with name \"{0}\" has not been registered, please check EPiServerFramwork.config file.", virtualPathProviderName), "virtualPathProviderName");
}
string storePath = storeVirtualPathProviderSettings.Parameters["physicalPath"];
string storeUrl = storeVirtualPathProviderSettings.Parameters["virtualPath"];
if (string.IsNullOrEmpty(storePath) || string.IsNullOrEmpty(storeUrl))
{
throw new ConfigurationErrorsException(@"Target virtual path provider is not well configured, ""physicalPath"" and ""virtualPath"" parameters are required.");
}
_storePath = VirtualPathUtilityEx.RebasePhysicalPath(storePath);
_storeUrl = Url.Parse(storeUrl);
if (!Directory.Exists(_storePath))
{
Directory.CreateDirectory(_storePath);
}
}
示例3: RegisterEntryPointControllerDescriptionBuilder
private static void RegisterEntryPointControllerDescriptionBuilder(this IComponentProvider container, Url entryPoint)
{
container.Register<IHttpControllerDescriptionBuilder, EntryPointControllerDescriptionBuilder>(
entryPoint.ToString().Substring(1),
() => new EntryPointControllerDescriptionBuilder(entryPoint, container.Resolve<IDefaultValueRelationSelector>()),
Lifestyles.Singleton);
}
示例4: Response
public Response(String message, Url address)
{
var buffer = Encoding.UTF8.GetBytes(message);
_content = new MemoryStream(buffer);
_headers = new Dictionary<String, String>();
_address = address;
}
示例5: Account
internal Account(Newtonsoft.Json.Linq.JToken json) : this()
{
IsDeactivated = (bool)json["deactivated"];
IsWithdrawalHalted = (bool)json["withdrawal_halted"];
IsSweepEnabled = (bool)json["sweep_enabled"];
OnlyPositionClosingTrades = (bool)json["only_position_closing_trades"];
UpdatedAt = (DateTime)json["updated_at"];
AccountUrl = new Url<Account>((string)json["url"]);
PortfolioUrl = new Url<AccountPortfolio>((string)json["portfolio"]);
UserUrl = new Url<User>((string)json["user"]);
PositionsUrl = new Url<AccountPositions>((string)json["positions"]);
AccountNumber = (string)json["account_number"];
AccountType = (string)json["type"];
Sma = json["sma"];
SmaHeldForOrders = json["sma_held_for_orders"];
MarginBalances = json["margin_balances"];
MaxAchEarlyAccessAmount = (decimal)json["max_ach_early_access_amount"];
CashBalance = new Balance(json["cash_balances"]);
}
示例6: RewriteUrl
public string RewriteUrl(string url)
{
if(url.Contains("productid"))
{
// Give it a thorough look - see if we can redirect it
Url uri = new Url(url);
string[] productIds = uri.QueryCollection.GetValues("productid");
if(productIds != null && productIds.Any())
{
string productId = productIds.FirstOrDefault();
if (productId != null && string.IsNullOrEmpty(productId) == false)
{
SearchResults<FindProduct> results = SearchClient.Instance.Search<FindProduct>()
.Filter(p => p.Code.MatchCaseInsensitive(productId))
.GetResult();
if (results.Hits.Any())
{
// Pick the first one
SearchHit<FindProduct> product = results.Hits.FirstOrDefault();
return product.Document.ProductUrl;
}
}
}
}
return null;
}
示例7: action_Click
protected void action_Click(object sender, EventArgs e)
{
string url = input.Text;
if (string.IsNullOrEmpty(url))
{
return;
}
// Execute methods on the UrlShortener service based upon the type of the URL provided.
try
{
string resultURL;
if (IsShortUrl(url))
{
// Expand the URL by using a Url.Get(..) request.
Url result = _service.Url.Get(url).Fetch();
resultURL = result.LongUrl;
}
else
{
// Shorten the URL by inserting a new Url.
Url toInsert = new Url { LongUrl = url};
toInsert = _service.Url.Insert(toInsert).Fetch();
resultURL = toInsert.Id;
}
output.Text = string.Format("<a href=\"{0}\">{0}</a>", resultURL);
}
catch (GoogleApiException ex)
{
output.Text = ex.ToHtmlString();
}
}
示例8: ResolveUrl
public string ResolveUrl(Url url)
{
if (url == null) return string.Empty;
var parsedUrl = ResolveUrl(PageReference.ParseUrl(url.OriginalString));
return string.IsNullOrWhiteSpace(parsedUrl) ? url.OriginalString : parsedUrl;
}
示例9: Download
public Download(Task<IResponse> task, CancellationTokenSource cts, Url target, INode originator)
{
_task = task;
_cts = cts;
_target = target;
_originator = originator;
}
示例10: Position
internal Position(Newtonsoft.Json.Linq.JToken json)
: this()
{
InstrumentUrl = new Url<Account>((string)json["instrument"]);
AverageBuyPrice = (decimal)json["average_buy_price"];
Quantity = (decimal)json["quantity"];
}
示例11: RawPage
/// <summary>
/// Initializes a new instance of the <see cref="RawPage" /> class.
/// </summary>
/// <param name="uri">The uri to the page on the site</param>
/// <param name="textData">Raw text of the page.</param>
/// <param name="links">Links recovered from this page.</param>
/// <param name="alternativePaths">The path the request was redirected to.</param>
public RawPage(Uri uri, string textData, string reference, IEnumerable<Uri> links, params string[] alternativePaths)
{
if (uri == null)
{
throw new ArgumentNullException("uri");
}
if (string.IsNullOrWhiteSpace(textData))
{
throw new ArgumentNullException("textData");
}
if (links == null)
{
throw new ArgumentNullException("links");
}
this.path = uri.PathAndQuery;
this.url = new Url(uri);
this.textData = textData;
this.links = links.ToList();
var alternative = (alternativePaths ?? Enumerable.Empty<string>())
.Where(p => p != path);
this.alternativePaths.AddRange(alternative);
this.reference = reference;
}
示例12: FlurlClient
public FlurlClient(Url url, bool autoDispose) {
this.Url = url;
this.AutoDispose = autoDispose;
this.AllowedHttpStatusRanges = new List<string>();
if (FlurlHttp.Configuration.AllowedHttpStatusRange != null)
this.AllowedHttpStatusRanges.Add(FlurlHttp.Configuration.AllowedHttpStatusRange);
}
示例13: GetSitemapData
public SitemapData GetSitemapData(string requestUrl)
{
var url = new Url(requestUrl);
var host = url.Path.TrimStart('/').ToLowerInvariant();
return GetAllSitemapData().FirstOrDefault(x => GetHostWithLanguage(x) == host && (x.SiteUrl == null || x.SiteUrl.Contains(url.Host)));
}
示例14: VirtualResponse
private VirtualResponse()
{
_address = Url.Create("http://localhost/");
_status = HttpStatusCode.OK;
_headers = new Dictionary<String, String>();
_content = MemoryStream.Null;
_dispose = false;
}
示例15: UrlWithHttpAsResourceIsARelativeUrl
public void UrlWithHttpAsResourceIsARelativeUrl()
{
var address = "http";
var result = new Url(address);
Assert.That(result.IsInvalid, Is.False);
Assert.That(result.Href, Is.EqualTo("http"));
Assert.That(result.IsRelative, Is.True);
}