本文整理汇总了C#中IAppBuilder.UseFileServer方法的典型用法代码示例。如果您正苦于以下问题:C# IAppBuilder.UseFileServer方法的具体用法?C# IAppBuilder.UseFileServer怎么用?C# IAppBuilder.UseFileServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAppBuilder
的用法示例。
在下文中一共展示了IAppBuilder.UseFileServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configuration
public void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(config);
var appFolder = Path.Combine(Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.FullName, "Webportal");
appBuilder.UseFileServer(new Microsoft.Owin.StaticFiles.FileServerOptions
{
RequestPath = new PathString(WebPortalUrl),
FileSystem = new PhysicalFileSystem(appFolder),
EnableDirectoryBrowsing = true
});
appBuilder.Map(PathString.Empty, a => a.Use<PortalRedirectionMiddelware>(WebPortalUrl));
appBuilder.Use<AdminMiddleware>();
}
示例2: Configuration
public void Configuration(IAppBuilder app)
{
#if DEBUG
app.UseErrorPage();
#endif
// Remap '/' to '.\defaults\'.
// Turns on static files and default files.
app.UseFileServer(new FileServerOptions()
{
RequestPath = PathString.Empty,
FileSystem = new PhysicalFileSystem(@".\defaults"),
});
// Only serve files requested by name.
app.UseStaticFiles("/files");
// Turns on static files, directory browsing, and default files.
app.UseFileServer(new FileServerOptions()
{
RequestPath = new PathString("/public"),
EnableDirectoryBrowsing = true,
});
// Browse the root of your application (but do not serve the files).
// NOTE: Avoid serving static files from the root of your application or bin folder,
// it allows people to download your application binaries, config files, etc..
app.UseDirectoryBrowser(new DirectoryBrowserOptions()
{
RequestPath = new PathString("/src"),
FileSystem = new PhysicalFileSystem(@""),
});
// Anything not handled will land at the welcome page.
app.UseWelcomePage();
}
示例3: Configuration
// Invoked once at startup to configure your application.
public void Configuration(IAppBuilder builder)
{
// Allow directory browsing from a specific dir.
builder.UseFileServer(options =>
{
options.WithRequestPath("/browse");
options.WithPhysicalPath("public");
options.WithDirectoryBrowsing();
});
// Allow file access to a specific dir.
builder.UseFileServer(options =>
{
options.WithRequestPath("/non-browse");
options.WithPhysicalPath("protected");
});
// Serve default files out of the specified directory for the root url.
builder.UseFileServer(options =>
{
options.WithRequestPath("/");
options.WithPhysicalPath("protected");
// options.WithDefaultFileNames(new[] { "index.html" }); // Already included by default.
});
builder.UseType<ServeSpecificPage>(@"protected\CustomErrorPage.html");
}
示例4: Configuration
public void Configuration(IAppBuilder app)
{
var appOptions = new FileServerOptions
{
RequestPath = new PathString("/app"),
FileSystem = new PhysicalFileSystem("app"),
EnableDefaultFiles = true
};
appOptions.DefaultFilesOptions.DefaultFileNames.Add("index.html");
appOptions.StaticFileOptions.ServeUnknownFileTypes = true;
app.UseFileServer(appOptions);
var libsOptions = new FileServerOptions
{
RequestPath = new PathString("/libs"),
FileSystem = new PhysicalFileSystem("libs")
};
libsOptions.StaticFileOptions.ServeUnknownFileTypes = true;
app.UseFileServer(libsOptions);
app.UseErrorPage();
app.MapSignalR();
}
示例5: Configuration
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
//HttpConfiguration config = new HttpConfiguration();
//config.Routes.MapHttpRoute(
// name: "DefaultWebApi",
// routeTemplate: "api/{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
//);
//app.UseWebApi(config);
var physicalFileSystem = new PhysicalFileSystem(@"./Plugins");
var options = new FileServerOptions {
EnableDefaultFiles = true,
FileSystem = physicalFileSystem
};
options.StaticFileOptions.FileSystem = physicalFileSystem;
options.StaticFileOptions.ServeUnknownFileTypes = true;
options.DefaultFilesOptions.DefaultFileNames = new[]
{
"Index.html"
};
app.UseFileServer(options);
app.MapSignalR();
}
示例6: Configuration
// This code configures Web API. The Startup class is specified as a type
// parameter in the WebApp.Start method.
public void Configuration(IAppBuilder appBuilder)
{
var config = new HttpConfiguration();
//config.Routes.MapHttpRoute(
// name: "DefaultApi",
// routeTemplate: "api/{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
//);
// web api
config.MapHttpAttributeRoutes();
// static files
appBuilder.UseFileServer(new FileServerOptions
{
FileSystem = new EmbeddedResourceFileSystem(typeof(Startup).Assembly, "Jukebox.Device.Web")
});
config.EnsureInitialized();
appBuilder.UseWebApi(config);
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
}
示例7: Configuration
public void Configuration(IAppBuilder app)
{
// app.UseFilter(req => req.TraceOutput.WriteLine(
// "{0} {1}{2} {3}",
// req.Method, req.PathBase, req.Path, req.QueryString));
app.UseErrorPage();
// app.Use(typeof(AutoTuneMiddleware), app.Properties["Microsoft.Owin.Host.HttpListener.OwinHttpListener"]);
app.UseSendFileFallback();
app.UseType<CanonicalRequestPatterns>();
app.UseFileServer(opt => opt.WithPhysicalPath("Public"));
app.MapPath("/static-compression", map => map
.UseStaticCompression()
.UseFileServer(opt =>
{
opt.WithDirectoryBrowsing();
opt.WithPhysicalPath("Public");
}));
app.MapPath("/danger", map => map
.UseStaticCompression()
.UseFileServer(opt =>
{
opt.WithDirectoryBrowsing();
opt.StaticFileOptions.ServeUnknownFileTypes = true;
}));
app.UseDiagnosticsPage("/testpage");
}
示例8: Configuration
// This code configures Web API. The Startup class is specified as a type
// parameter in the WebApp.Start method.
public void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
HttpConfiguration config = ConfigurationBuilder.HttpConfiguration;
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute("MyROute", "jobs/{name}/trigger", new {controller = "Jobs", action = "PostTriggerJob"});
appBuilder.UseFileServer(new FileServerOptions()
{
FileSystem = new PhysicalFileSystem("./Assets/assets"),
RequestPath = new PathString("/assets")
});
appBuilder.Map("/quartzadmin", builder => builder.UseNancy());
appBuilder.Map("/api", builder => builder.UseWebApi(config));
//appBuilder.UseWebApi(config);
}
示例9: ConfigureFileServer
private void ConfigureFileServer(IAppBuilder app, HostConfig config)
{
// use a file server to serve all static content (js, css, content, html, ...) and also configure default files (eg: index.html to be the default entry point)
// create file system that will locate the files
var fileSystem = AggregateFileSystem.FromWebUiPhysicalPaths(config.RootDirectory);
// setup default documents
app.UseDefaultFiles(new DefaultFilesOptions
{
FileSystem = fileSystem,
DefaultFileNames = new List<string>
{
"views/index.html"
}
});
// start file server to share website static content
// wrapper around: StaticFiles + DefaultFiles + DirectoryBrowser
var fileServerOptions = new FileServerOptions
{
EnableDirectoryBrowsing = false,
FileSystem = fileSystem,
};
fileServerOptions.StaticFileOptions.ContentTypeProvider = new FileServerContentTypeProvider();
app.UseFileServer(fileServerOptions);
}
示例10: Configuration
public void Configuration(IAppBuilder app)
{
#if DEBUG
app.UseErrorPage();
#endif
app.Use(
async (context, next) =>
{
// Log all exceptions and incoming requests
Console.WriteLine("{0} {1} {2}", context.Request.Method, context.Request.Path, context.Request.QueryString);
try
{
await next();
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
throw;
}
});
var contentFileSystem = new PhysicalFileSystem("Content");
app.UseBabel(new BabelFileOptions() { StaticFileOptions = new StaticFileOptions() { FileSystem = contentFileSystem }});
app.UseFileServer(new FileServerOptions() { FileSystem = contentFileSystem });
app.Use<CommentsMiddleware>();
}
示例11: Configuration
// This code configures Web API. The Startup class is specified as a type
// parameter in the WebApp.Start method.
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
app.UseWebApi(config);
var root = Directory.GetParent(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)).Parent.FullName;
var physicalFileSystem = new PhysicalFileSystem(root);
var options = new FileServerOptions
{
EnableDefaultFiles = true,
FileSystem = physicalFileSystem
};
options.StaticFileOptions.FileSystem = physicalFileSystem;
options.StaticFileOptions.ServeUnknownFileTypes = true;
options.DefaultFilesOptions.DefaultFileNames = new[]
{
"app\\index.html"
};
app.UseFileServer(options);
}
示例12: Configuration
public void Configuration(IAppBuilder appBuilder)
{
var physicalFileSystem = new PhysicalFileSystem(@"C:\Work\Advanced\ACSStarTrek\ACS.Client");
var options = new FileServerOptions
{
EnableDefaultFiles = true,
FileSystem = physicalFileSystem
};
options.StaticFileOptions.FileSystem = physicalFileSystem;
options.StaticFileOptions.ServeUnknownFileTypes = true;
options.DefaultFilesOptions.DefaultFileNames = new[]
{
"index.html"
};
appBuilder.UseFileServer(options);
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(config);
}
示例13: Configuration
public void Configuration(IAppBuilder app)
{
// STEP Map Folder Paths
const string clientRootFolder = @"..\..\..\";
DirectoryInfo webDirectory = null;
webDirectory = new DirectoryInfo(clientRootFolder + @"Sitter.Client\src\build");
ValidateDirectory(webDirectory);
// Path to index
var fsOptions = new FileServerOptions
{
EnableDirectoryBrowsing = true,
FileSystem = new PhysicalFileSystem(webDirectory.FullName)
};
app.UseFileServer(fsOptions);
// Self-host the WebApi
var config = new HttpConfiguration();
WebApiConfig.Register(config);
IoCConfig.Register(config);
app.UseWebApi(config);
}
示例14: Configuration
// This code configures Web API. The Startup class is specified as a type
// parameter in the WebApp.Start method.
public void Configuration(IAppBuilder appBuilder)
{
var options = new FileServerOptions()
{
RequestPath = new PathString(""),
FileSystem = new PhysicalFileSystem("client"),
EnableDefaultFiles = true,
EnableDirectoryBrowsing = true
};
options.DefaultFilesOptions.DefaultFileNames.Add("index.html");
options.StaticFileOptions.ServeUnknownFileTypes = true;
appBuilder.MapSignalR();
appBuilder.UseFileServer(options);
var config = new HttpConfiguration();
ConfigureDependancyResolver(config);
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{employeeId}");
appBuilder.UseCors(CorsOptions.AllowAll);
appBuilder.UseWebApi(config);
}
示例15: Configuration
public void Configuration(IAppBuilder appBuilder)
{
HttpConfiguration config = new HttpConfiguration();
PhysicalFileSystem physicalFileSystem = new PhysicalFileSystem(@".\wwwroot");
FileServerOptions fileOptions = new FileServerOptions();
fileOptions.EnableDefaultFiles = true;
fileOptions.RequestPath = PathString.Empty;
fileOptions.FileSystem = physicalFileSystem;
fileOptions.DefaultFilesOptions.DefaultFileNames = new[] {"Default.html"};
fileOptions.StaticFileOptions.FileSystem = fileOptions.FileSystem = physicalFileSystem;
fileOptions.StaticFileOptions.ServeUnknownFileTypes = true;
FormatterConfig.ConfigureFormatters(config.Formatters);
RouteConfig.RegisterRoutes(config);
appBuilder.UseWebApi(config);
appBuilder.UseFileServer(fileOptions);
//CORS & SignalR
appBuilder.UseCors(CorsOptions.AllowAll);
HubConfiguration configR = new HubConfiguration();
configR.EnableDetailedErrors = true;
appBuilder.MapSignalR(configR);
GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => new SignalRUserIdProvider());
config.EnsureInitialized();
}