Deleted stale files from earlier deleted test website UrlHelperWebSite
This commit is contained in:
parent
ed93a6c812
commit
a208c95a4f
|
|
@ -1,68 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
using Microsoft.AspNet.Mvc.Infrastructure;
|
|
||||||
using Microsoft.AspNet.Mvc.Routing;
|
|
||||||
using Microsoft.Extensions.OptionsModel;
|
|
||||||
|
|
||||||
namespace UrlHelperWebSite
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Following are some of the scenarios exercised here:
|
|
||||||
/// 1. Based on configuration, generate Content urls pointing to local or a CDN server
|
|
||||||
/// 2. Based on configuration, generate lower case urls
|
|
||||||
/// </summary>
|
|
||||||
public class CustomUrlHelper : UrlHelper
|
|
||||||
{
|
|
||||||
private readonly AppOptions _options;
|
|
||||||
|
|
||||||
public CustomUrlHelper(ActionContext actionContext, AppOptions options)
|
|
||||||
: base(actionContext)
|
|
||||||
{
|
|
||||||
_options = options;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Depending on config data, generates an absolute url pointing to a CDN server
|
|
||||||
/// or falls back to the default behavior
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="contentPath"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override string Content(string contentPath)
|
|
||||||
{
|
|
||||||
if (_options.ServeCDNContent
|
|
||||||
&& contentPath.StartsWith("~/", StringComparison.Ordinal))
|
|
||||||
{
|
|
||||||
var segment = new PathString(contentPath.Substring(1));
|
|
||||||
|
|
||||||
return ConvertToLowercaseUrl(_options.CDNServerBaseUrl + segment);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ConvertToLowercaseUrl(base.Content(contentPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string RouteUrl(UrlRouteContext routeContext)
|
|
||||||
{
|
|
||||||
return ConvertToLowercaseUrl(base.RouteUrl(routeContext));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Action(UrlActionContext actionContext)
|
|
||||||
{
|
|
||||||
return ConvertToLowercaseUrl(base.Action(actionContext));
|
|
||||||
}
|
|
||||||
|
|
||||||
private string ConvertToLowercaseUrl(string url)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(url)
|
|
||||||
&& _options.GenerateLowercaseUrls)
|
|
||||||
{
|
|
||||||
return url.ToLowerInvariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
using Microsoft.AspNet.Mvc.Routing;
|
|
||||||
using Microsoft.Extensions.OptionsModel;
|
|
||||||
|
|
||||||
namespace UrlHelperWebSite
|
|
||||||
{
|
|
||||||
public class CustomUrlHelperFactory : IUrlHelperFactory
|
|
||||||
{
|
|
||||||
private readonly AppOptions _options;
|
|
||||||
|
|
||||||
public CustomUrlHelperFactory(IOptions<AppOptions> options)
|
|
||||||
{
|
|
||||||
_options = options.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IUrlHelper GetUrlHelper(ActionContext context)
|
|
||||||
{
|
|
||||||
return new CustomUrlHelper(context, _options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using Microsoft.AspNet.Builder;
|
|
||||||
using Microsoft.AspNet.Mvc.Routing;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace UrlHelperWebSite
|
|
||||||
{
|
|
||||||
public class Startup
|
|
||||||
{
|
|
||||||
// Set up application services
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
|
||||||
{
|
|
||||||
services.Configure<AppOptions>(optionsSetup =>
|
|
||||||
{
|
|
||||||
optionsSetup.ServeCDNContent = true;
|
|
||||||
optionsSetup.CDNServerBaseUrl = "http://cdn.contoso.com";
|
|
||||||
optionsSetup.GenerateLowercaseUrls = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add MVC services to the services container
|
|
||||||
services.AddMvc();
|
|
||||||
|
|
||||||
services.AddSingleton<IUrlHelperFactory, CustomUrlHelperFactory>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app)
|
|
||||||
{
|
|
||||||
app.UseCultureReplacer();
|
|
||||||
|
|
||||||
|
|
||||||
// Add MVC to the request pipeline
|
|
||||||
app.UseMvc(routes =>
|
|
||||||
{
|
|
||||||
routes.MapRoute("Default", "{controller=Home}/{action=Index}");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue