asp.net-web-api2

WebApi routing - many POST methods

纵饮孤独 提交于 2019-12-23 01:41:55
问题 I have WebAPI 2 application. How can I specify 2 or more POST methods? I have the following WebApiConfig: public static void Register(HttpConfiguration config) { config.SuppressDefaultHostAuthentication(); config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } and API

WebApi routing - many POST methods

笑着哭i 提交于 2019-12-23 01:41:49
问题 I have WebAPI 2 application. How can I specify 2 or more POST methods? I have the following WebApiConfig: public static void Register(HttpConfiguration config) { config.SuppressDefaultHostAuthentication(); config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } and API

webapi and unhandled exception hook per appdomain

早过忘川 提交于 2019-12-23 01:12:52
问题 Having a WebApi 2.2 application - is it possible to make use of AppDomain's UnhandledException hook? I have a code similar to this: [assembly: OwinStartup("DevConfiguration", typeof(DevStartup))] namespace WebApi.Module { public class DevStartup { private const string ErrorEventSourceName = "WebApiHost"; private const int ErrorEventId = 600; [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)] public void Configuration(IAppBuilder app) { AppDomain

ASP.NET WEB API 2 - ModelBinding Firing twice per request

落花浮王杯 提交于 2019-12-22 18:45:24
问题 I have a custom validation attribute, that when I make a request to the server via a POST, is firing the IsValid method on the attribute twice. Its resulting in the error message returned to be duplicated. I've checked using Fiddler that the request is only ever fired once, so the situation is 1 request with model binding firing twice. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public class MinimumAgeAttribute :

404 Error when calling for the metadata using WEB API OData v4

不羁的心 提交于 2019-12-22 10:44:00
问题 I have tested the the call to the $metadata using postman and have found that when the MaxDataServiceVersion header is supplied the service always returns a 404 error. I have other posts about this using Breeze, but the best answer I can find simply says to comment out the line that adds this header. We are using SAPUI5 ODataModel in our client application and commenting out that header is not an option. Web API Config: ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

Bearer token that never expires

为君一笑 提交于 2019-12-22 10:43:30
问题 Is it possible define that ASP.NET Web API 2 bearer token that never expires? Any clue? 回答1: I don't think you can set it to never expire but you could certainly set a longer AccessTokenExpireTimeSpan : OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString("/Token"), Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory), AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"), AccessTokenExpireTimeSpan = TimeSpan.FromDays(14

Custom Json.NET JsonConverter is not being called while deserializing Web.API parameter

人盡茶涼 提交于 2019-12-22 10:39:07
问题 I have a Web.API endpoint that takes an object like this as a parameter: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } public UserName UserName { get; set; } } For example: [Route("api/person")] [AcceptVerbs("POST")] public void UpdatePerson(Person person) { // etc. } I've defined a custom JsonConverter to convert from a JSON string property to my custom UserName class: public class UserNameJsonDeserializer :

.NET WebApi How to prevent “$ref”: “x” output of JSON

僤鯓⒐⒋嵵緔 提交于 2019-12-22 10:38:37
问题 I'm Using Web Api with Entity Framework, I have a controller named as Gift, when client GET's the API I'm getting all Gifts from DB by using entity framework and and returning it as JSON Here is my controller function public List<Gift> Get() { return GiftService.GetIncludeAndActive(); } Here is Service Function public List<Gift> GetIncludeAndActive() { return dbSet.Include("GiftCategory").Where(x => x.Status == Model.Enums.GiftStatus.Active).OrderByDescending(x => x.Featured).ThenBy(x => x

Asp.net Web API 2 and mixed Authentication using both Integrated Windows and Token based

房东的猫 提交于 2019-12-22 10:08:20
问题 I have an asp.net Web API server running under IIS, that until now has used windows authentication as it has only had other services running on the same domain conencting to it. So, in my web.config I have the following settings... <system.web> <compilation debug="true" targetFramework="4.5.1" /> <httpRuntime targetFramework="4.5.1" /> <authentication mode="Windows" /> </system.web> <system.webServer> <security> <authentication> <windowsAuthentication enabled="true" /> </authentication> <

Url Referrer is not available in WebApi 2 MVC project

最后都变了- 提交于 2019-12-22 09:40:15
问题 I have an MVC WebAPI 2 project with a Controllers controller. The Method I'm trying to call is POST (Create). I need to access the referring URL that called that method yet, no matter what object I access, the referring URL either doesn't exist in the object or is null. For example, I've added the HTTPContext reference and the following returns null : var thingythingthing = HttpContext.Current.Request.UrlReferrer; The Request object does not have a UrlReferrer property. This returns null as