// 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.StaticFiles;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNet.Builder
{
///
/// Extension methods for the StaticFileMiddleware
///
public static class StaticFileExtensions
{
///
/// Enables static file serving for the current request path
///
///
///
public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder app)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
return app.UseMiddleware();
}
///
/// Enables static file serving for the given request path
///
///
/// The relative request path.
///
public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder app, string requestPath)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
return app.UseStaticFiles(new StaticFileOptions
{
RequestPath = new PathString(requestPath)
});
}
///
/// Enables static file serving with the given options
///
///
///
///
public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder app, StaticFileOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return app.UseMiddleware(Options.Create(options));
}
}
}