本文整理汇总了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>();
}
示例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(
}
示例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();
}
示例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());
}
示例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);
}
示例6: ConfigureMobileApp
public static void ConfigureMobileApp(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
config.EnableCors(new EnableCorsAttribute("*", "*", "*", "*"));
config.MapHttpAttributeRoutes();
config.EnableSystemDiagnosticsTracing();
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = 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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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()
});
}
}
示例12: Configuration
public void Configuration(IAppBuilder app)
{
HttpConfiguration httpConfiguration = new HttpConfiguration();
WebApiConfig.Register(httpConfiguration);
app.UseWebApi(httpConfiguration);
}
示例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);
}
示例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);
}
示例15: Configuration
// This method is required by Katana:
public void Configuration(IAppBuilder app)
{
var webApiConfiguration = ConfigureWebApi();
app.UseCors(CorsOptions.AllowAll);
app.UseWebApi(webApiConfiguration);
}