本文整理汇总了C#中IApplicationBuilder.UseFileServer方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseFileServer方法的具体用法?C# IApplicationBuilder.UseFileServer怎么用?C# IApplicationBuilder.UseFileServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IApplicationBuilder
的用法示例。
在下文中一共展示了IApplicationBuilder.UseFileServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment environment)
{
// Route all unknown requests to app root
app.Use(async (context, next) =>
{
await next();
// If there's no available file and the request doesn't contain an extension, we're probably trying to access a page.
// Rewrite request to use app root
if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value))
{
context.Request.Path = "/app/index.html";
await next();
}
});
// Serve wwwroot as root
app.UseFileServer();
var nodeModulesPath =
Path.Combine(environment.ContentRootPath, "node_modules");
createFolderIfItDoesNotExist(nodeModulesPath);
// Serve /node_modules as a separate root (for packages that use other npm modules client side)
app.UseFileServer(new FileServerOptions()
{
// Set root of file server
FileProvider = new PhysicalFileProvider(nodeModulesPath),
// Only react to requests that match this path
RequestPath = "/node_modules",
// Don't expose file system
EnableDirectoryBrowsing = false
});
}
示例2: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//use session
app.UseSession();
app.UseFileServer();
var provider = new PhysicalFileProvider(
Path.Combine(_contentRootPath, "node_modules")
);
var _fileServerOptions = new FileServerOptions();
_fileServerOptions.RequestPath = "/node_modules";
_fileServerOptions.StaticFileOptions.FileProvider = provider;
_fileServerOptions.EnableDirectoryBrowsing = true;
app.UseFileServer(_fileServerOptions);
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
//if (env.IsDevelopment())
//{
// app.UseDeveloperExceptionPage();
// app.UseDatabaseErrorPage();
// app.UseBrowserLink();
//}
//else
//{
// app.UseExceptionHandler("/Home/Error");
//}
app.UseStatusCodePagesWithRedirects("~/Home/StatusCodePage");
app.UseExceptionHandler("/Home/Error");
app.UseStaticFiles();
app.UseIdentity();
// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseFacebookAuthentication(new FacebookOptions()
{
AppId = Configuration["Authentication:Facebook:AppId"],
AppSecret = Configuration["Authentication:Facebook:AppSecret"]
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areaAdmin",
template: "{area:exists}/{controller}/{action}/{id?}",
defaults: new {controller="Home", action = "Index" }
);
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
//SampleData.InitializeDatabaseAsync(app.ApplicationServices).Wait();
}
示例3: Configure
public void Configure(IApplicationBuilder app, IApplicationEnvironment environemnt)
{
app.UseIISPlatformHandler();
app.UseFileServer();
var provider = new PhysicalFileProvider(Path.Combine(environemnt.ApplicationBasePath, "node_modules"));
var options = new FileServerOptions();
options.RequestPath = "/node_modules";
options.StaticFileOptions.FileProvider = provider;
options.EnableDirectoryBrowsing = true;
app.UseFileServer(options);
app.UseMvc();
}
示例4: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// Add the platform handler to the request pipeline.
app.UseIISPlatformHandler();
app.UseFileServer();
}
示例5: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseFileServer(new FileServerOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"MyStaticFiles")),
RequestPath = new PathString("/StaticFiles"),
EnableDirectoryBrowsing = true
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例6: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Use different settings depending on debug or production builds
if (env.IsDevelopment())
{
// Register the Microsoft default Error Handler
app.UseDeveloperExceptionPage();
// Register the ASP.NET Runtime Info Page
app.UseRuntimeInfoPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
// Shows an error page when there is a 400 - 599 error
app.UseStatusCodePagesWithRedirects("/Home/Error");
// Register MVC Middleware AND specify the routing format
app.UseMvc(routes => routes.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}"));
// Register the File Server Middleware
app.UseFileServer();
}
示例7: Configure
public void Configure(IApplicationBuilder app)
{
var config = new Configuration();
config.AddEnvironmentVariables();
config.AddJsonFile("config.json");
config.AddJsonFile("config.dev.json", true);
config.AddUserSecrets();
var password = config.Get("password");
if (config.Get<bool>("RecreateDatabase"))
{
var context = app.ApplicationServices.GetService<Models.BlogDataContext>();
context.Database.EnsureDeleted();
System.Threading.Thread.Sleep(2000);
context.Database.EnsureCreated();
}
if (config.Get<bool>("debug"))
{
app.UseErrorPage();
app.UseRuntimeInfoPage();
}
else
{
app.UseErrorHandler("/home/error");
}
app.UseMvc(routes => routes.MapRoute(
"Default", "{controller=Home}/{action=Index}/{id?}"));
app.UseFileServer();
}
示例8: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.UseFileServer();
app.UseSignalR<RawConnection>("/raw-connection");
app.UseSignalR();
}
示例9: Configure
public void Configure(IApplicationBuilder app)
{
/* Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline.
* Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production.
*/
app.UseErrorPage(ErrorPageOptions.ShowAll);
//Configure SignalR
app.UseSignalR();
//Serves static files in the application.
app.UseFileServer();
//Configure WebFx
app.UseMvc(routes =>
{
routes.MapRoute(
null,
"{controller}/{action}",
new { controller = "Home", action = "Index" });
routes.MapRoute(
null,
"api/{controller}/{action}",
new { controller = "Home", action = "Index" });
routes.MapRoute(
null,
"api/{controller}",
new { controller = "Home" });
});
}
示例10: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
app.UseDeveloperExceptionPage();
app.UseExceptionHandler("/home/error");
app.UseReact(config =>
{
config
.SetLoadBabel(false)
.AddScriptWithoutTransform("~/lib/generated/bundle.react.js");
});
app.UseStaticFiles();
app.UseFileServer();
app.UseMvc(routes =>
routes.MapRoute("Default",
"{controller=Home}/{action=Index}/{id?}")
);
app.Use(async (context, next) =>
{
if (context.Request.Path.Value.StartsWith("/hello"))
await context.Response.WriteAsync("Hello World!");
if (context.Request.Path.Value.StartsWith("/checkout"))
await context.Response.WriteAsync("Hello World!");
next();
});
}
示例11: Configure
public void Configure(IApplicationBuilder app)
{
app.UseFileServer(new FileServerOptions
{
EnableDefaultFiles = true
});
}
示例12: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
//app.UseIISPlatformHandler();
//app.UseStaticFiles();
// only for dev
//app.UseDeveloperExceptionPage();
//app.UseRuntimeInfoPage();
//production
//app.UseExceptionHandler("/home/error");
app.UseMvc(routes =>
routes.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}"));
//app.UseFileServer();
//// Enable all static file middleware (serving of static files, default files,
//// and directory browsing) for the MyStaticFiles directory.
app.UseFileServer(new FileServerOptions()
{
//FileProvider = new PhysicalFileProvider(@"D:\Source\WebApplication1\src\WebApplication1\MyStaticFiles"),
//RequestPath = new PathString("/StaticFiles"),
EnableDirectoryBrowsing = false
});
//app.Run(async (context) =>
//{
// await context.Response.WriteAsync("Hello World!");
//});
app.UseIISPlatformHandler();
}
示例13: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// Setup configuration sources. May be unnecessary
var builder = new ConfigurationBuilder().SetBasePath(env.ContentRootPath).AddJsonFile("appsettings.json").AddEnvironmentVariables(); ;
Configuration = builder.Build();
loggerFactory.AddConsole();
serviceHelpers.rootPath = env.ContentRootPath;
// Add Error handling middleware which catches all application specific errors and
// sends the request to the following path or controller action.
app.UseExceptionHandler("/Home/Error");
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{player?}",
defaults: new { controller = "Player", action = "Index" }
);
routes.MapRoute(
name: "Robot",
template: "{controller}/{action}/{bot?}"
);
});
app.UseFileServer();
app.UseSignalR();
}
示例14: Configure
public void Configure(IApplicationBuilder app)
{
app.UseMvc(routes => routes.MapRoute(
"Default", "{controller=Posts}/{action=Create}/{id?}"));
app.UseFileServer();
}
示例15: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole((category, level) =>
{
if (category.StartsWith("Microsoft."))
{
return level >= LogLevel.Information;
}
return level >= LogLevel.Verbose;
});
app.UseStatusCodePages();
app.UseFileServer();
app.UseRequestLocalization(new RequestCulture("en-US"));
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute("areaRoute", "{area:exists}/{controller}/{action}");
routes.MapRoute(
"controllerActionRoute",
"{controller}/{action}",
new { controller = "Home", action = "Index" },
constraints: null,
dataTokens: new { NameSpace = "default" });
routes.MapRoute(
"controllerRoute",
"{controller}",
new { controller = "Home" });
});
}