asp.net-web-api2

Autofac IAutofacActionFilter execution order for Web API 2

▼魔方 西西 提交于 2020-01-07 01:48:10
问题 Are there any ways to set the order of execution on web api action filters registered with Autofac? Currently, if I register the following: builder.Register(x => new MyFirstAttribute(x.Resolve<IMyService>())).AsWebApiActionFilterFor<ApiController>().InstancePerRequest(); builder.Register(x => new MySecondAttribute(x.Resolve<IMyService>())).AsWebApiActionFilterFor<ApiController>().InstancePerRequest(); it is 'unknown' which will be executing first and second. Even if I'd create a new

Specify a unique identifier attribute for an object across webapi Models

独自空忆成欢 提交于 2020-01-07 00:58:27
问题 In a POST call to a WebApi I am trying to return a Created(newobject) thing. But there is no signature for Created in ApiController that can only take the object and do the rest. It works fine if I return something like: return Created(newobject.blahid.ToString(), newobject); or if I do a return CreatedAtRoute("DefaultApi", new { controller = ControllerContext.ControllerDescriptor.ControllerName, id = newobject.blahid.ToString()}, newobject); I want to simplify this to: return Created

Specify a unique identifier attribute for an object across webapi Models

折月煮酒 提交于 2020-01-07 00:58:08
问题 In a POST call to a WebApi I am trying to return a Created(newobject) thing. But there is no signature for Created in ApiController that can only take the object and do the rest. It works fine if I return something like: return Created(newobject.blahid.ToString(), newobject); or if I do a return CreatedAtRoute("DefaultApi", new { controller = ControllerContext.ControllerDescriptor.ControllerName, id = newobject.blahid.ToString()}, newobject); I want to simplify this to: return Created

Error “405 Method Not Allow” When Calling Put method in Postman with body parameter

橙三吉。 提交于 2020-01-07 00:35:40
问题 I was trying to call the Put method through Postman and always getting error: "405 Method Not Allow" and "Message": "The requested resource does not support http method 'PUT'." I'm using DocumentDB and C#. Here is my code: [Route("multilanguage/Resources/{id}/{Language}")] [HttpPut] public async Task<IHttpActionResult> UpdateResource(string Id, string Language, string text) { client = new DocumentClient(new Uri(EndPoint), AuthKey); var collectionLink = UriFactory.CreateDocumentCollectionUri

Change Content-Type header for HttpResponseMessage

雨燕双飞 提交于 2020-01-06 20:15:16
问题 I am returning a crossdomain.xml file from WeB APi 2, and I need the Content-Type header to be "application/xml" or "text/xml". This is my controller: public class CrossDomainController : ApiController { public HttpResponseMessage Get() { var xmlString = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "crossdomain.xml"); var result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new StringContent(xmlString, Encoding.UTF8, "text/xml"); return result; } } I have also

No connection string could be found in the application config file (But it Does Exist)

半世苍凉 提交于 2020-01-06 15:04:21
问题 I have a web API project I published to IIS and it complains there is no connection string with a specific name in my config file. I verified there is an entry in my web.config file of the web API project so it must not be picking it up. I was able to run this same web.config file locally using Visual Studio 2013. I am well aware the referenced start up project must have the connection string and that is the case for me. I verified my web API project has the connection string below (same one

What are the pros and cons of having a WebAPI in the same or different project [closed]

孤街醉人 提交于 2020-01-06 13:09:33
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . I have an MVC application and the solution consist of three project as described below: Store.Domain : Holds the domain entities and logic (repositories created with the Entity Framework). Store.WebUI : Holds the controllers and views; acts as the UI for the application.

Html Example Response with Swagger and Swashbuckle

醉酒当歌 提交于 2020-01-06 11:48:30
问题 I have a .NET Web API 2 app, with a controller method that returns HTML. I want to provide sample HTML in the swagger docs, but I can't get anything to show. This is what I have: [HttpGet] [SwaggerResponse(HttpStatusCode.OK, Type = typeof(string))] [SwaggerResponse(HttpStatusCode.NotFound)] [SwaggerResponseContentType("text/html", Exclusive = true)] [SwaggerResponseExamples(typeof(string), typeof(ExampleProvider))] public async Task<HttpResponseMessage> Get(Guid id) { var example = GetExample

IdentityServer 4 get timestamp while login/refresh token

拈花ヽ惹草 提交于 2020-01-06 08:11:03
问题 We are using identity server 4 to protect the api/resources. One of the requirements is to trace the user activity which means, the last time the user consumed the api (not logged in but consumed). As we have 30+ apis, we thought it would be easrier to intercept this validation process/event to register in the database the last activity date once the token gets validated against the identity server . My question here, does this validation really happens on identity server level each and every

How to use AutoMapper 9.0.0 in Asp.Net Web Api 2 without dependency injection?

北城以北 提交于 2020-01-06 07:53:56
问题 I haven't been able to find any info where to put this code inside my project. Right now I am use using this in each action I need the mapper. Is there a better way to do this with out dependency injection? var config = new MapperConfiguration(cfg => { cfg.CreateMap<Source, Dest>(); }); IMapper iMapper = config.CreateMapper(); var destList= iMapper.Map<Dest[]>(sourceList); 回答1: Dependency injection added a whole level of complexity to my legacy project that I just didn't want to deal with. 9