当前位置: 首页>>代码示例>>C#>>正文


C# IApplicationBuilder.UseFileServer方法代码示例

本文整理汇总了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
            });
        }
开发者ID:SSWConsulting,项目名称:enterprise-musicstore-ui-angular2,代码行数:35,代码来源:Startup.cs

示例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();
        }
开发者ID:XcodeFi,项目名称:Project-MVC6-angular2,代码行数:57,代码来源:Startup.cs

示例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();            
 }
开发者ID:danielyefet,项目名称:ngclass,代码行数:14,代码来源:Startup.cs

示例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();
        }
开发者ID:Foffles,项目名称:CraftToolbox,代码行数:8,代码来源:Startup.cs

示例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?}");
            });
        }
开发者ID:crestin,项目名称:Docs,代码行数:33,代码来源:StartupUseFS.cs

示例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();
        }
开发者ID:Pycorax,项目名称:SP4Unity,代码行数:26,代码来源:Startup.cs

示例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();
        }
开发者ID:lukehammer,项目名称:AspNetBlog,代码行数:34,代码来源:Startup.cs

示例8: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            app.UseFileServer();

            app.UseSignalR<RawConnection>("/raw-connection");
            app.UseSignalR();
        }
开发者ID:bestwpw,项目名称:SignalR-Server,代码行数:7,代码来源:Startup.cs

示例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" });
        });
    }
开发者ID:rvfvazquez,项目名称:BugTracker,代码行数:32,代码来源:Startup.cs

示例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();
     });
 }
开发者ID:mpatil-sapient,项目名称:mfinity_public,代码行数:26,代码来源:Startup.cs

示例11: Configure

 public void Configure(IApplicationBuilder app)
 {
     app.UseFileServer(new FileServerOptions
     {
         EnableDefaultFiles = true
     });
 }
开发者ID:lynkx,项目名称:westminster,代码行数:7,代码来源:Startup.cs

示例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();
        }
开发者ID:kotha16,项目名称:aspnetcoredemos,代码行数:35,代码来源:Startup.cs

示例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();
        }
开发者ID:ShVerni,项目名称:RoboRuckus,代码行数:33,代码来源:Startup.cs

示例14: Configure

        public void Configure(IApplicationBuilder app)
        {
            app.UseMvc(routes => routes.MapRoute(
                "Default", "{controller=Posts}/{action=Create}/{id?}"));

            app.UseFileServer();
        }
开发者ID:mortl,项目名称:AspNet-Blog,代码行数:7,代码来源:Startup.cs

示例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" });
            });
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:34,代码来源:Startup.cs


注:本文中的IApplicationBuilder.UseFileServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。