本文整理汇总了C#中System.Web.Http.HttpConfiguration类的典型用法代码示例。如果您正苦于以下问题:C# HttpConfiguration类的具体用法?C# HttpConfiguration怎么用?C# HttpConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpConfiguration类属于System.Web.Http命名空间,在下文中一共展示了HttpConfiguration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Register
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
// Web API routes
config.MapHttpAttributeRoutes();
// enable CORS
config.EnableCors();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "PlayerApi",
routeTemplate: "api/{controller}/{action}/{name}",
defaults: new { teamName = RouteParameter.Optional }
);
}
开发者ID:cs262G-TeamGr8,项目名称:WebAPI,代码行数:25,代码来源:WebApiConfig.cs
示例2: Register
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
//Unity
var container = new UnityContainer();
container.RegisterType<IUnitOfWork, UnitOfWork>(new HierarchicalLifetimeManager());
container.RegisterType<IGenericRepository<Farmacia>, GenericRepository<Farmacia>>(new HierarchicalLifetimeManager());
config.DependencyResolver = new UnityResolver(container);
//Formatters
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
//GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
//config.Formatters.Insert(0, new System.Net.Http.Formatting.JsonMediaTypeFormatter());
// Web API routes
config.MapHttpAttributeRoutes();
//config.EnableCors();
var cors = new EnableCorsAttribute("http://localhost:28285", "*", "*");
config.EnableCors(cors);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
开发者ID:RubenGomes10,项目名称:Farma,代码行数:30,代码来源:WebApiConfig.cs
示例3: Register
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
}
开发者ID:JonCubed,项目名称:owin-webapi2-sample,代码行数:7,代码来源:WebApiConfig.cs
示例4: ByPostShouldReturnCorrectResponse
public void ByPostShouldReturnCorrectResponse()
{
var controller = typeof(CategoriesController);
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
var httpServer = new HttpServer(config);
var httpInvoker = new HttpMessageInvoker(httpServer);
using (httpInvoker)
{
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://test.com/api/categories/1"),
Method = HttpMethod.Get
};
var result = httpInvoker.SendAsync(request, CancellationToken.None).Result;
Assert.IsNotNull(result);
}
}
开发者ID:Team-Hypnos,项目名称:Gallery,代码行数:30,代码来源:CategoriesIntegrationTests.cs
示例5: Register
public static void Register(HttpConfiguration config)
{
config.EnableCors();
// Web API configuration and services
var clientID = WebConfigurationManager.AppSettings["auth0:ClientId"];
var clientSecret = WebConfigurationManager.AppSettings["auth0:ClientSecret"];
config.MessageHandlers.Add(new JsonWebTokenValidationHandler()
{
Audience = clientID,
SymmetricKey = clientSecret
});
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "WithActionApi",
routeTemplate: "api/{controller}/{action}/{fillupId}"
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
开发者ID:derekchisholm,项目名称:CarsiteWebAPI,代码行数:28,代码来源:WebApiConfig.cs
示例6: Register
public static void Register(HttpConfiguration configuration)
{
container = new WindsorContainer();
container.Install(FromAssembly.This());
container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel, true));
configuration.Services.Replace(typeof (IHttpControllerActivator), new WindsorCompositionRoot(container));
}
开发者ID:jeremielumandong,项目名称:RailWaySample,代码行数:7,代码来源:WindsorConfig.cs
示例7: 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
示例8: Register
public static void Register(HttpConfiguration config)
{
//// Web API configuration and services
//// Web API routes
config.MapHttpAttributeRoutes();
//config.Routes.MapHttpRoute(
// name: "DefaultApi",
// routeTemplate: "api/{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
//);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("type", "json", new MediaTypeHeaderValue("application/json")));
GlobalConfiguration.Configuration.Formatters.XmlFormatter.MediaTypeMappings.Add(new QueryStringMapping("type", "xml", new MediaTypeHeaderValue("application/xml")));
// Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
// To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
// For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
//config.EnableQuerySupport();
// To disable tracing in your application, please comment out or remove the following line of code
// For more information, refer to: http://www.asp.net/web-api
//config.EnableSystemDiagnosticsTracing();
}
开发者ID:rasadeyan,项目名称:RestlessHoneySeeker,代码行数:31,代码来源:WebApiConfig.cs
示例9: RouteRequest
public static RouteInfo RouteRequest(HttpConfiguration config, HttpRequestMessage request)
{
// create context
var controllerContext = new HttpControllerContext(config, Substitute.For<IHttpRouteData>(), request);
// get route data
var routeData = config.Routes.GetRouteData(request);
RemoveOptionalRoutingParameters(routeData.Values);
request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;
controllerContext.RouteData = routeData;
// get controller type
var controllerDescriptor = new DefaultHttpControllerSelector(config).SelectController(request);
controllerContext.ControllerDescriptor = controllerDescriptor;
// get action name
var actionMapping = new ApiControllerActionSelector().SelectAction(controllerContext);
return new RouteInfo
{
Controller = controllerDescriptor.ControllerType,
Action = actionMapping.ActionName
};
}
开发者ID:vefve,项目名称:StreamusServer,代码行数:25,代码来源:Helpers.cs
示例10: 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
示例11: AttriubteRouting_SelectsExpectedControllerAndAction
[InlineData("GET", "http://localhost/Customers(12)/NS.SpecialCustomer/NS.GetSalary()", "GetSalaryFromSpecialCustomer_12")] // call function on derived entity type
public async Task AttriubteRouting_SelectsExpectedControllerAndAction(string method, string requestUri,
string expectedResult)
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
var controllers = new[] { typeof(CustomersController), typeof(MetadataAndServiceController), typeof(OrdersController) };
TestAssemblyResolver resolver = new TestAssemblyResolver(new MockAssembly(controllers));
HttpConfiguration config = new HttpConfiguration();
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.Services.Replace(typeof(IAssembliesResolver), resolver);
config.MapODataServiceRoute("odata", "", model.Model);
HttpServer server = new HttpServer(config);
config.EnsureInitialized();
HttpClient client = new HttpClient(server);
HttpRequestMessage request = new HttpRequestMessage(new HttpMethod(method), requestUri);
// Act
var response = await client.SendAsync(request);
// Assert
if (!response.IsSuccessStatusCode)
{
Assert.False(true, await response.Content.ReadAsStringAsync());
}
var result = await response.Content.ReadAsAsync<AttributeRoutingTestODataResponse>();
Assert.Equal(expectedResult, result.Value);
}
开发者ID:richarddwelsh,项目名称:aspnetwebstack,代码行数:33,代码来源:AttributeRoutingTest.cs
示例12: Configure
public static void Configure(HttpConfiguration config)
{
// Message Handlers
config.MessageHandlers.Add(new RequireHttpsMessageHandler());
config.MessageHandlers.Add(new PingYourPackageAuthHandler());
//Formatters
var jqueryFormatter = config.Formatters.FirstOrDefault(
x => x.GetType() ==
typeof(JQueryMvcFormUrlEncodedFormatter));
config.Formatters.Remove(
config.Formatters.FormUrlEncodedFormatter);
config.Formatters.Remove(jqueryFormatter);
foreach (var formatter in config.Formatters)
{
formatter.RequiredMemberSelector =
new SuppressedRequiredMemberSelector();
}
// Filters
config.Filters.Add(
new InvalidModelStateFilterAttribute());
//Default Services
config.Services.Replace(typeof(IContentNegotiator), new DefaultContentNegotiator(
excludeMatchOnTypeOnly: true));
config.Services.RemoveAll(typeof(ModelValidatorProvider), validator => !(validator
is DataAnnotationsModelValidatorProvider));
// ParameterBindingRules
config.ParameterBindingRules.Insert(0,descriptor => typeof(IRequestCommand).IsAssignableFrom(descriptor.ParameterType)? new FromUriAttribute().GetBinding(descriptor) : null);
}
开发者ID:dotnext24,项目名称:PingYourPackage,代码行数:34,代码来源:WebAPIConfig.cs
示例13: Register
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// 取消注释下面的代码行可对具有 IQueryable 或 IQueryable<T> 返回类型的操作启用查询支持。
// 若要避免处理意外查询或恶意查询,请使用 QueryableAttribute 上的验证设置来验证传入查询。
// 有关详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=279712。
//config.EnableQuerySupport();
// 若要在应用程序中禁用跟踪,请注释掉或删除以下代码行
// 有关详细信息,请参阅: http://www.asp.net/web-api
config.EnableSystemDiagnosticsTracing();
// 参考:http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v3/creating-an-odata-endpoint
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Products");
// 参考:http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v3/working-with-entity-relations
builder.EntitySet<Supplier>("Suppliers");
//config.Routes.MapODataRoute("OData", "odata", builder.GetEdmModel());
config.Routes.MapODataServiceRoute("ODataRoute", "odata", builder.GetEdmModel());
}
开发者ID:SunriseSamples,项目名称:ODataTest,代码行数:25,代码来源:WebApiConfig.cs
示例14: Register
public static void Register(HttpConfiguration config) {
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new {id = RouteParameter.Optional}
);
}
开发者ID:Binzzzz,项目名称:Durandal,代码行数:7,代码来源:WebApiConfig.cs
示例15: Register
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
//clear default formatters
config.Formatters.Clear();
config.Formatters.Add(new JsonMediaTypeFormatter());
//set formatters only json
var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First();
//optional: set serializer settings here
config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter));
//jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
开发者ID:alexaung,项目名称:OBTS,代码行数:27,代码来源:WebApiConfig.cs
示例16: RegisterWebApiRoutes
public static void RegisterWebApiRoutes(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "AccountApi",
routeTemplate: "api/account/{action}/{id}",
defaults: new { controller = "Account", id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "BreezeDefault",
routeTemplate: "breeze/{action}",
defaults: new { Controller = "Metadata" }
);
config.Routes.MapHttpRoute(
name: "BreezeModule",
routeTemplate: "breeze/{controller}/{action}"
);
config.EnableQuerySupport();
}
开发者ID:jorgeguevara,项目名称:DurandalAuth,代码行数:27,代码来源:RouteConfig.cs
示例17: 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
示例18: Generator
public Generator(HttpConfiguration conf, HttpRequestMessage req)
{
config = conf;
request = req;
GenerateRouteData();
}
开发者ID:nestalk,项目名称:MvcRouteTester,代码行数:7,代码来源:Generator.cs
示例19: Register
public static void Register(HttpConfiguration config)
{
//// Uncomment the following to use the documentation from XML documentation file.
//config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
//// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
//// Also, the string arrays will be used for IEnumerable<string>. The sample objects will be serialized into different media type
//// formats by the available formatters.
//config.SetSampleObjects(new Dictionary<Type, object>
//{
// {typeof(string), "sample string"},
// {typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
//});
//// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
//// and have IEnumerable<string> as the body parameter or return type.
//config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");
//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
//// on the controller named "Values" and action named "Get" with parameter "id".
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
//config.SetActualRequestType(typeof(string), "Values", "Get");
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
//config.SetActualResponseType(typeof(string), "Values", "Post");
}
开发者ID:cstrobbe,项目名称:C4A-TVM,代码行数:34,代码来源:HelpPageConfig.cs
示例20: RegisterRoutes
public void RegisterRoutes(HttpConfiguration config)
{
// blobs
this.MapRoute(config, HttpMethod.Get , "api/file", "Blob", "Get");
this.MapRoute(config, HttpMethod.Post, "api/file", "Blob", "Post");
// nomenclatures
this.MapRoute(config, HttpMethod.Get, "api/nomenclatures/{alias}/{id}" , "Nom", "GetNom", new Dictionary<string, object>() { {"id", new IntRouteConstraint() } });
this.MapRoute(config, HttpMethod.Get, "api/nomenclatures/{alias}/{valueAlias}", "Nom", "GetNom");
this.MapRoute(config, HttpMethod.Get, "api/nomenclatures/{alias}" , "Nom", "GetNoms");
// signs
this.MapRoute(config, HttpMethod.Post, "api/signXml", "Sign", "PostSignXml");
this.MapRoute(config, HttpMethod.Post, "api/signOffice", "Sign", "PostSignOffice");
//user
this.MapRoute(config, HttpMethod.Get, "api/user/currentData", "User", "GetUserData");
this.MapRoute(config, HttpMethod.Get, "api/user/duplicateUnit", "User", "CheckDuplicateUnit");
this.MapRoute(config, HttpMethod.Get, "api/users", "User", "GetUsers");
this.MapRoute(config, HttpMethod.Get, "api/users/{id}", "User", "GetUser");
this.MapRoute(config, HttpMethod.Post, "api/users/{id}", "User", "UpdateUser");
this.MapRoute(config, HttpMethod.Post, "api/users", "User", "CreateUser");
this.MapRoute(config, HttpMethod.Post, "api/user/changePassword", "User", "ChangeCurrentUserPassword");
this.MapRoute(config, HttpMethod.Post, "api/user/isCorrectPassword", "User", "IsCorrectPassword");
//role
this.MapRoute(config, HttpMethod.Get, "api/roles", "User", "GetRoles");
}
开发者ID:MartinBG,项目名称:Gva,代码行数:29,代码来源:CommonApiWebApiConfig.cs
注:本文中的System.Web.Http.HttpConfiguration类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论