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


C# IAppBuilder.UseWebApi方法代码示例

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


在下文中一共展示了IAppBuilder.UseWebApi方法的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>();
        }
开发者ID:jormenjanssen,项目名称:Soundboard,代码行数:25,代码来源:PortalStartup.cs

示例2: 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 = new HttpConfiguration();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            // 默认返回Json数据
            //config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

            //var bson = new BsonMediaTypeFormatter();
            //bson.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/bson"));
            //config.Formatters.Add(bson);
            config.Formatters.Add(new Raven.AspNet.WebApiExtensions.Formatters.MsgPackFormatter());

            appBuilder.UseRequestScopeContext();
            appBuilder.UseWebApi(config);
            
            //CallContext
            //appBuilder.Use(
        }
开发者ID:Indifer,项目名称:Raven.Rpc.HttpProtocol,代码行数:27,代码来源:Startup.cs

示例3: Configuration

 public void Configuration(IAppBuilder appBuilder)
 {
     var config = new HttpConfiguration();
     config.MapHttpAttributeRoutes();
     config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new {id = RouteParameter.Optional});
     appBuilder.UseWebApi(config).UseNancy();
 }
开发者ID:cryosharp,项目名称:endersjson,代码行数:7,代码来源:Startup.cs

示例4: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseIdentityServerBearerTokenAuthentication(
                new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = ExpenseTrackerConstants.IdSrv,
                RequiredScopes = new[] { "expensetrackerapi" }
            });

            app.UseWebApi(WebApiConfig.Register());


            app.UseWebApi(WebApiConfig.Register()); 
             
        }
开发者ID:bkcrux,项目名称:WebAPIDemo,代码行数:15,代码来源:Startup.cs

示例5: Configuration

 public static void Configuration(IAppBuilder builder)
 {
     HttpConfiguration configuration = new HttpConfiguration();
     configuration.Routes.MapODataServiceRoute("odata", null, GetEdmModel())
         .MapODataRouteAttributes(configuration); // Enable attribute routing.
     builder.UseWebApi(configuration);
 }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:7,代码来源:ODataAttributeRoutingSample.cs

示例6: ConfigureMobileApp

        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();
            config.EnableCors(new EnableCorsAttribute("*", "*", "*", "*"));
            config.MapHttpAttributeRoutes();
            config.EnableSystemDiagnosticsTracing();
            config.Formatters.JsonFormatter.SerializerSettings.Re‌​ferenceLoopHandling = ReferenceLoopHandling.Ignore;

            new MobileAppConfiguration()
                .UseDefaultConfiguration()
                .ApplyTo(config);

            Database.SetInitializer(new ContosoMomentsDBInitializer());

            ConfigureStorage();

            // set up auth for local development
            //app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions() {
            //    SigningKey = ConfigurationManager.AppSettings["authSigningKey"],
            //    ValidAudiences = new[] { ConfigurationManager.AppSettings["authAudience"] },
            //    ValidIssuers = new[] { ConfigurationManager.AppSettings["authIssuer"] },
            //    TokenHandler = config.GetAppServiceTokenHandler()
            //});

            // Increases the HTTP Connection Pool.
            ServicePointManager.DefaultConnectionLimit = 100;

            app.UseWebApi(config);
        }
开发者ID:lindydonna,项目名称:ContosoMoments,代码行数:29,代码来源:Startup.MobileApp.cs

示例7: Configuration

        public void Configuration(IAppBuilder app)
        {
            var config = new HttpConfiguration();

            // Web API routes
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });

            // Remove XML formatter
            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            // NetIn and assign a dependency resolver for Web API to use.
            var dependencyResolver = new DependencyResolver();
            config.DependencyResolver = dependencyResolver;

            // Filter for loggering
            var logActionFilter = new Containerizer.Filters.LogActionFilter(DependencyResolver.logger);
            config.Filters.Add(logActionFilter);
            var exceptionLoggingFilter = new Containerizer.Filters.ExceptionLoggingFilter(DependencyResolver.logger);
            config.Filters.Add(exceptionLoggingFilter);

            // Make sure the Autofac lifetime scope is passed to Web API.
            app.UseAutofacWebApi(config);

            app.MapWebSocketPattern<ContainerProcessHandler>("/api/containers/(?<handle>.*)/run", dependencyResolver);

            app.UseWebApi(config);
        }
开发者ID:stefanschneider,项目名称:garden-windows,代码行数:30,代码来源:Startup.cs

示例8: Configuration

        public void Configuration(IAppBuilder app)
        {
            var config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();

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

            OAuthOptions = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath = new PathString("/Token"),
                Provider = new ApplicationOAuthProvider(),
                AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
                // Note: Remove the following line before you deploy to production:
                AllowInsecureHttp = true
            };

            // Enable the application to use bearer tokens to authenticate users
            app.UseOAuthBearerTokens(OAuthOptions);

            app.UseWebApi(config);
        }
开发者ID:FabianGosebrink,项目名称:ASPNET-WebAPI-TokenAuthentication,代码行数:26,代码来源:Startup.cs

示例9: Configuration

        public void Configuration(IAppBuilder app)
        {
            // initialize cors
            app.UseCors(CorsOptions.AllowAll);

            // initialize authentication
            app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
                AuthenticationMode = AuthenticationMode.Active,
                ExpireTimeSpan = TimeSpan.FromHours(1),
                SlidingExpiration = true                
            });

            // initialize webapi
            HttpConfiguration config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "Default",
                routeTemplate: "{controller}/{id}",
                defaults: new 
                { 
                    id = RouteParameter.Optional 
                });

            // initialize dependency injection
            ConfigureDependencies(app, config);

            // bind web api
            app.UseWebApi(config);
        }
开发者ID:nascentdigital,项目名称:web-template,代码行数:31,代码来源:Startup.cs

示例10: ConfigureMobileApp

        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

#if DEBUG
            config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;

            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
#endif

            new MobileAppConfiguration().UseDefaultConfiguration().ApplyTo(config);

            config.Services.Add(typeof(IExceptionLogger), new AiExceptionLogger());

            // Use Entity Framework Code First to create database tables based on your DbContext
            Database.SetInitializer(new MobileServiceInitializer());

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    // This middleware is intended to be used locally for debugging. By default, HostName will
                    // only have a value when running in an App Service application.
                    SigningKey = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler = config.GetAppServiceTokenHandler()
                });
            }

            app.UseWebApi(config);
        }
开发者ID:xamarin,项目名称:app-crm,代码行数:34,代码来源:Startup.MobileApp.cs

示例11: Configuration

        public void Configuration(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            new MobileAppConfiguration()
                .UseDefaultConfiguration()
                .ApplyTo(config);

            app.UseWebApi(config);

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    // This middleware is intended to be used locally for debugging. By default, HostName will
                    // only have a value when running in an App Service application.
                    SigningKey = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler = config.GetAppServiceTokenHandler()
                });
            }
        }
开发者ID:Sirikon,项目名称:HealthClinic.biz,代码行数:25,代码来源:Startup.cs

示例12: Configuration

        public void Configuration(IAppBuilder app)
        {
            HttpConfiguration httpConfiguration = new HttpConfiguration();
            WebApiConfig.Register(httpConfiguration);

            app.UseWebApi(httpConfiguration);
        }
开发者ID:vitorsalgado,项目名称:crap,代码行数:7,代码来源:ApiStartup.cs

示例13: Configuration

        public void Configuration(IAppBuilder app)
        {
            var config = new HttpConfiguration();

            config.Routes.MapHttpRoute(
                "DefaultApi", "api/{controller}/{id}", new {id = RouteParameter.Optional});

            var builder = new ContainerBuilder();

            // Register Web API controller in executing assembly.
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            // Register a logger service to be used by the controller and middleware.
            builder.Register(c => new Logger()).As<ILogger>().InstancePerRequest();

            // Autofac will add middleware to IAppBuilder in the order registered.
            // The middleware will execute in the order added to IAppBuilder.
            builder.RegisterType<FirstMiddleware>().InstancePerRequest();
            builder.RegisterType<SecondMiddleware>().InstancePerRequest();

            var container = builder.Build();

            // Create and assign a dependency resolver for Web API to use.
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            // This should be the first middleware added to the IAppBuilder.
            app.UseAutofacMiddleware(container);

            // Make sure the Autofac lifetime scope is passed to Web API.
            app.UseAutofacWebApi(config);

            app.UseWebApi(config);
        }
开发者ID:Mart-Bogdan,项目名称:autofac-examples,代码行数:33,代码来源:Startup.cs

示例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)
 {
     // Configure Web API for self-host.
     var config = new HttpConfiguration();
     config.MapHttpAttributeRoutes();
     appBuilder.UseWebApi(config);
 }
开发者ID:kurtdevocht,项目名称:ScratchCanTalk,代码行数:9,代码来源:Startup.cs

示例15: Configuration

 // This method is required by Katana:
 public void Configuration(IAppBuilder app)
 {
     var webApiConfiguration = ConfigureWebApi();
     
     app.UseCors(CorsOptions.AllowAll);            
     app.UseWebApi(webApiConfiguration);
 }
开发者ID:valpioner,项目名称:Ukrland,代码行数:8,代码来源:Startup.cs


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