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


C# IAppBuilder.UseStaticFiles方法代码示例

本文整理汇总了C#中IAppBuilder.UseStaticFiles方法的典型用法代码示例。如果您正苦于以下问题:C# IAppBuilder.UseStaticFiles方法的具体用法?C# IAppBuilder.UseStaticFiles怎么用?C# IAppBuilder.UseStaticFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAppBuilder的用法示例。


在下文中一共展示了IAppBuilder.UseStaticFiles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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)
        {

            appBuilder.UseFileServer(new FileServerOptions()
            {
                RequestPath = PathString.Empty,
                FileSystem = new PhysicalFileSystem(@".\")
            });

            appBuilder.UseStaticFiles("/Views");
            appBuilder.UseStaticFiles("/Scripts");
            appBuilder.UseStaticFiles("/js");
            appBuilder.UseStaticFiles("/Content");

            // Configure Web API for self-host. 
            HttpConfiguration config = new HttpConfiguration();

            //  Enable attribute based routing
            //  http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2
            config.MapHttpAttributeRoutes();

            // Remove the XML formatter
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            config.Routes.MapHttpRoute(
                name: "AfterglowAPI",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            appBuilder.UseWebApi(config);
        } 
开发者ID:DigiM4x,项目名称:Afterglow,代码行数:34,代码来源:AppHost.cs

示例2: ConfigureStaticContent

        private static void ConfigureStaticContent(IAppBuilder app)
        {
            // TODO: When Owin.Compression reaches a more mature state, use that for compression

            app.UseStaticFiles(new StaticFileOptions
            {
                RequestPath = new PathString("/css"),
                FileSystem = new PhysicalFileSystem("Public/Styles")
            });

            app.UseStaticFiles(new StaticFileOptions
            {
                RequestPath = new PathString("/js"),
                FileSystem = new PhysicalFileSystem("Public/Scripts")
            });

            app.UseStaticFiles(new StaticFileOptions
            {
                RequestPath = new PathString("/fonts"),
                FileSystem = new PhysicalFileSystem("Public/Fonts")
            });

            app.UseStaticFiles(new StaticFileOptions
            {
                RequestPath = new PathString("/avatars"),
                FileSystem = new PhysicalFileSystem("Public/Images/Avatars")
            });
        }
开发者ID:CumpsD,项目名称:CC.TheBench,代码行数:28,代码来源:Startup.cs

示例3: Configuration

 public void Configuration(IAppBuilder app)
 {
     string strUseRedis = CloudConfigurationManager.GetSetting("UseRedis") ?? "false";
     bool useRedis = bool.Parse(strUseRedis);
     var dependencyResolver = new UnityDependencyResolver();
     UnityWireupConfiguration.WireUp(dependencyResolver);
     GlobalHost.DependencyResolver = dependencyResolver;
     var options = new CookieAuthenticationOptions()
     {
         AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
         LoginPath = new PathString("/"),
         LogoutPath = new PathString("/")
     };
     app.UseCookieAuthentication(options);
     app.Use(async (context, next) =>
     {
         if (context.Request.Path.Value.Equals("/") ||
         context.Request.Path.Value.StartsWith("/public", StringComparison.CurrentCultureIgnoreCase))
         {
             await next();
         }
         else if (context.Request.User == null || !context.Request.User.Identity.IsAuthenticated)
         {
             context.Response.StatusCode = 401;
         }
         else
         {
             await next();
         }
     });
     HttpConfiguration webApiConfiguration = new HttpConfiguration();
     webApiConfiguration.DependencyResolver = dependencyResolver;
     webApiConfiguration.MapHttpAttributeRoutes();
     app.UseWebApi(webApiConfiguration);
     RedisConfiguration redisConfiguration = dependencyResolver.Resolve<RedisConfiguration>();
     if (redisConfiguration.UseRedis)
     {
         GlobalHost.DependencyResolver.UseRedis(redisConfiguration.HostName, redisConfiguration.Port, redisConfiguration.Password, redisConfiguration.EventKey);
     }
     app.MapSignalR();
     var sharedOptions = new SharedOptions()
     {
         RequestPath = new PathString(string.Empty),
         FileSystem =
             new PhysicalFileSystem(".//public//content")
     };
     app.UseDefaultFiles(new Microsoft.Owin.StaticFiles.DefaultFilesOptions(sharedOptions)
     {
         DefaultFileNames = new List<string>() { "index.html" }
     });
     app.UseStaticFiles("/public");
     app.UseStaticFiles("/content");
     app.UseStaticFiles("/scripts");
     app.UseStaticFiles("/styles");
     app.UseStaticFiles(new StaticFileOptions(sharedOptions));
 }
开发者ID:asifashraf,项目名称:proSignalR,代码行数:56,代码来源:Startup.cs

示例4: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.Use<RedwoodApp>(HostingEnvironment.ApplicationPhysicalPath);
            app.UseStaticFiles();

            RedwoodConfiguration.Default.RouteTable.MapPageRoute<TaskListPresenter>("");
        }
开发者ID:jechtom,项目名称:Redwood,代码行数:7,代码来源:Startup.cs

示例5: Configuration

        public void Configuration(IAppBuilder app)
        {
            // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888

            // Static file support.
            var baseDir = AppDomain.CurrentDomain.BaseDirectory;
            app.UseStaticFiles(new StaticFileOptions
            {
                FileSystem = new PhysicalFileSystem(root: baseDir),
                ServeUnknownFileTypes = false
            });

            // ASP.NET Web API support.
            var config = new HttpConfiguration();
            
            // Fix: CORS support of WebAPI doesn't work on mono. http://stackoverflow.com/questions/31590869/web-api-2-post-request-not-working-on-mono
            if (Type.GetType("Mono.Runtime") != null) config.MessageHandlers.Add(new MonoPatchingDelegatingHandler());

            config.EnableCors();
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
            app.UseWebApi(config);

            // NancyFx support.
            app.UseNancy();
        }
开发者ID:jsakamoto,项目名称:chomado-problem-server,代码行数:30,代码来源:Startup.cs

示例6: DefaultStaticFiles

 public void DefaultStaticFiles(IAppBuilder app)
 {
     app.Use((context, next) => { context.Response.Headers["PassedThroughOWIN"] = "True"; return next(); });
     app.UseStaticFiles();
     app.Run(context => { context.Response.StatusCode = 402; return context.Response.WriteAsync("Fell Through"); });
     app.UseStageMarker(PipelineStage.MapHandler);
 }
开发者ID:Kstal,项目名称:Microsoft.Owin,代码行数:7,代码来源:StaticFilesTests.cs

示例7: Configuration

 public void Configuration(IAppBuilder app)
 {
     //app.UseStaticFiles(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),"Assets"));
     app.UseStaticFiles("/Assets");
     app.Use(typeof(RadMvcMiddleware));
     //app.UseWelcomePage();
 }
开发者ID:sgarver,项目名称:RadMVC,代码行数:7,代码来源:Startup.cs

示例8: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseFalcor("/model.json",
                routerFactory: config => new NetflixRouter(new FakeRatingService(), new RecommendationService.RecommendationService(), userId: 1));

            app.UseStaticFiles();
        }
开发者ID:gitter-badger,项目名称:falcor.net,代码行数:7,代码来源:Startup.cs

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

示例10: Configuration

 public void Configuration(IAppBuilder app)
 {
     
     app.UseStaticFiles("/Sample/Web");
     
     app.UseXSockets(true);
 }
开发者ID:suhas-achar,项目名称:XSockets.Samples,代码行数:7,代码来源:Program.cs

示例11: Configuration

 public static void Configuration(IAppBuilder app)
 {
     app.UseStaticFiles();
     app.Use(async (ctx, next) => {
         await ctx.Response.WriteAsync("Hello World");
     });
 }
开发者ID:walimi,项目名称:Pluralsight,代码行数:7,代码来源:Startup.cs

示例12: Configuration

        public void Configuration(IAppBuilder app)
        {
            var instrumentationKey = System.Configuration.ConfigurationManager.AppSettings.Get("Telemetry.InstrumentationKey");
            if (!string.IsNullOrEmpty(instrumentationKey))
            {
                // set it as early as possible to avoid losing telemetry
                TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
            }

            _searcherManager = CreateSearcherManager();

            //test console
            app.Use(async (context, next) =>
            {
                if (string.Equals(context.Request.Path.Value, "/console", StringComparison.OrdinalIgnoreCase))
                {
                    context.Response.Redirect(context.Request.PathBase + context.Request.Path + "/");
                    context.Response.StatusCode = 301;
                    return;
                }
                else if (string.Equals(context.Request.Path.Value, "/console/", StringComparison.OrdinalIgnoreCase))
                {
                    context.Request.Path = new PathString("/console/Index.html");
                }
                await next();
            });

            app.UseStaticFiles(new StaticFileOptions(new SharedOptions
            {
                RequestPath = new PathString("/console"),
                FileSystem = new EmbeddedResourceFileSystem(typeof(QueryMiddleware).Assembly, "NuGet.Services.Search.Console")
            }));

            app.Run(Invoke);
        }
开发者ID:darrelmiller,项目名称:NuGet.Services.Search,代码行数:35,代码来源:Startup.cs

示例13: Configuration

        public void Configuration(IAppBuilder app)
        {
            /* // Note: Enable only for debugging. This slows down the perf tests.
            app.Use((context, next) =>
            {
                var req = context.Request;
                context.TraceOutput.WriteLine("{0} {1}{2} {3}", req.Method, req.PathBase, req.Path, req.QueryString);
                return next();
            });*/

            app.UseErrorPage(new ErrorPageOptions { SourceCodeLineCount = 20 });
            // app.Use(typeof(AutoTuneMiddleware), app.Properties["Microsoft.Owin.Host.HttpListener.OwinHttpListener"]);
            app.UseSendFileFallback();
            app.Use<CanonicalRequestPatterns>();

            app.UseStaticFiles(new StaticFileOptions()
            {
                RequestPath = new PathString("/static"),
                FileSystem = new PhysicalFileSystem("public")
            });
            app.UseDirectoryBrowser(new DirectoryBrowserOptions()
            {
                RequestPath = new PathString("/static"),
                FileSystem = new PhysicalFileSystem("public")
            });
            app.UseStageMarker(PipelineStage.MapHandler);

            FileServerOptions options = new FileServerOptions();
            options.EnableDirectoryBrowsing = true;
            options.StaticFileOptions.ServeUnknownFileTypes = true;

            app.UseWelcomePage("/Welcome");
        }
开发者ID:Xamarui,项目名称:Katana,代码行数:33,代码来源:Startup.cs

示例14: Configuration

        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());
            Log.Logger = new LoggerConfiguration()
               .MinimumLevel.Debug()
               .WriteTo.Trace()
               .CreateLogger();

            app.UseAesDataProtectorProvider();
            app.Map("/admin", adminApp =>
                {
                    var factory = new IdentityManagerServiceFactory();
                   
                    factory.ConfigureSimpleIdentityManagerService("AspId");
                    //factory.ConfigureCustomIdentityManagerServiceWithIntKeys("AspId_CustomPK");

                    var adminOptions = new IdentityManagerOptions(){
                        Factory = factory
                    };
                    adminOptions.SecurityConfiguration.RequireSsl = false;
                    adminApp.UseIdentityManager(adminOptions);
                });

            var idSvrFactory = Factory.Configure();
            idSvrFactory.ConfigureUserService("AspId");

            var viewOptions = new ViewServiceOptions
            {
                TemplatePath = this.basePath.TrimEnd(new char[] { '/' })
            };
            idSvrFactory.ViewService = new IdentityServer3.Core.Configuration.Registration<IViewService>(new ViewService(viewOptions));

            var options = new IdentityServerOptions
            {
                SiteName = "IdentityServer3 - ViewSerive-AspNetIdentity",
                SigningCertificate = Certificate.Get(),
                Factory = idSvrFactory,
                RequireSsl = false,
                AuthenticationOptions = new AuthenticationOptions
                {
                    IdentityProviders = ConfigureAdditionalIdentityProviders,
                }
            };

            app.Map("/core", core =>
            {
                core.UseIdentityServer(options);
            });

            app.UseStaticFiles(new StaticFileOptions
            {
                RequestPath = new PathString("/Content"),
                FileSystem = new PhysicalFileSystem(Path.Combine(this.basePath, "Content")) 
            });

            var config = new HttpConfiguration();
          //  config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute("API", "api/{controller}/{action}", new { controller = "Home", action = "Get" });
            app.UseWebApi(config);
        }
开发者ID:mequanta,项目名称:Janitor-old,代码行数:60,代码来源:Startup.cs

示例15: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/")
            });

            SetupContainer();

            var applicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath;

            // use DotVVM
            DotvvmConfiguration dotvvmConfiguration = app.UseDotVVM(applicationPhysicalPath, true);
            dotvvmConfiguration.ServiceLocator.RegisterSingleton<IViewModelLoader>(() => new WindsorViewModelLoader(container));

            RegisterResources(dotvvmConfiguration);

            AddRoutes(dotvvmConfiguration);

            RegisterMappings();

            RegisterJsCompilables();

            // use static files
            app.UseStaticFiles(new StaticFileOptions()
            {
                FileSystem = new PhysicalFileSystem(applicationPhysicalPath)
            });
        }
开发者ID:Mylan719,项目名称:snowfur2016,代码行数:30,代码来源:Startup.cs


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