asp.net-web-api2

Web API Controller convert MemoryStream into StreamContent

心不动则不痛 提交于 2019-12-03 06:01:33
I have a large collection of images stored on a secured server some of which need to be displayed on a world facing portal. The portal's server is inside a DMZ which allows requests in but prevents direct requests from moving through to secured domain. The images are cataloged using SOLR and can be downloaded via an internal (apache?) server from http://intenalname/folderA/folderAB/file.jpg Inside my PhotoController I can create an instance of the WebClient , give it the url and get a MemoryStream . If I attempt to use this memory stream to populate the response.content I get an empty response

OWIN token authentication 400 Bad Request on OPTIONS from browser

别来无恙 提交于 2019-12-03 05:58:53
I am using token authentication for small project based on this article: http://bitoftech.net/2014/06/09/angularjs-token-authentication-using-asp-net-web-api-2-owin-asp-net-identity/ Everything seems to work fine except one thing: OWIN based token authentication doesn't allow OPTIONS request on /token endpoint. Web API returns 400 Bad Request and whole browser app stops sending POST request to obtain token. I have all CORS enabled in application as in sample project. Below some code that might be relevant: public class Startup { public static OAuthBearerAuthenticationOptions OAuthBearerOptions

WEB API JSON Serializing Circular References

 ̄綄美尐妖づ 提交于 2019-12-03 05:49:19
I'm trying to access the property fields (JSON) from the child entity that is received from Web API. By looking at the browser console, however, it is showing a reference instead of the fields. How do I get access to these fields? ANGULAR JS VIEW <table infinite-scroll='tF.loadMore()' infinite-scroll-disabled='tF.isBusy' infinite-scroll-distance='3' class="responsive"> <thead> <tr> <th>FIELD 1</th> <th>FIELD 2</th> <th>FIELD 3</th> <th>FIELD 4</th> <th>FIELD 5</th> </tr> </thead> <tbody> <tr ng-repeat="item in tF.items | filter:searchFilter"> <td>{{item.CompanyDomainModel.CompanyName}}</td>

ASP.NET Web API generate url using Url.Action

回眸只為那壹抹淺笑 提交于 2019-12-03 04:43:55
问题 How can I generate the same url but in Web Api ? var url = Url.Action("Action", "Controller", new { product = product.Id, price = price }, protocol: Request.Url.Scheme); P.S. The url should be generated to an MVC controller/action but from within web api. So basically: make a get request to my api/generateurl and that will return an url to : http://domain.com/controller/action?product=productId&price=100 回答1: Maybe the closest helper to Url.Action in Web Api Controller is the Url.Link method

Best way to have one Web API forward request to other

我的未来我决定 提交于 2019-12-03 04:35:02
问题 I have a few web services running on different servers, and I want to have one web service running "in front" of the rest to decide which web service (server) the request should be forwarded to based on header values. The idea is that a client will send a request, say: http://api.mysite.com/cars The API at mysite.com will inspect the request, extract information from the API key (which is supplied in the headers) and redirect to the appropriate server, e.g. http://server4.mysite.com/api/cars

How to integrate Autofac with WepApi 2 and Owin?

非 Y 不嫁゛ 提交于 2019-12-03 01:22:11
I am using this package to integrate Autofac with my WebApi Owin application: https://www.nuget.org/packages/Autofac.WebApi2.Owin And following this post: http://alexmg.com/owin-support-for-the-web-api-2-and-mvc-5-integrations-in-autofac/ My code in Startup.cs looks like this: var config = new HttpConfiguration(); IContainer container = EngineContext.InitializeEngine(); var dependencyResolver = new AutofacWebApiDependencyResolver(container); config.DependencyResolver = dependencyResolver; app.UseAutofacMiddleware(container); app.UseAutofacWebApi(config); WebApiConfig.Register(config); app

Web API Gzip not being applied

喜欢而已 提交于 2019-12-02 22:33:31
I have added the web.config entry to enable gzip compression based on this S/O answer Enable IIS7 gzip . I then checked the Chrome Developer window while loading an ASPX page and saw the header in the response: Cache-Control:private Content-Encoding:gzip Content-Length:3669 Content-Type:text/html; charset=utf-8 Date:Wed, 04 Mar 2015 00:46:05 GMT Server:Microsoft-IIS/7.5 Vary:Accept-Encoding X-AspNet-Version:4.0.30319 X-Powered-By:ASP.NET So that means it's "working", correct? But when looking for that header when making a Web API call, it is not present: Cache-Control:no-cache Content-Length

ASP.net Identity, IoC and sharing DbContext

半世苍凉 提交于 2019-12-02 21:25:17
Have anyone been successful in attaching an IoC with OWIN ASP.NET Identity to share the same DbContext as the WebApi (or MVC) application? I would like that if ASP.Net identity loads the user, it loads in the same dbcontext as used in the rest of the application. (using AutoFac as IoC - but wouldn't mind an example with other container) Edit : 06/Jan/2014: Just to be a bit more specific, when the ASP.Net identity attempts to use a DbContext it needs to be the same DbContext instance as the rest of the application. Otherwise it will create two instances of the same DbContext. I am already using

IHttpActionResult vs async Task<IHttpActionResult>

半腔热情 提交于 2019-12-02 20:23:13
Most Web API 2.0 methods I've seen return IHttpActionResult , which is defined as an interface that "defines a command that asynchronously creates a System.Net.Http.HttpResponseMessage". I'm a little confused about what's going on when a method is returning async Task<IHttpActionResult> . Why would you use one over the other? Or are these functionally identical - isn't IHttpActionResult already asynchronous? The difference between using IHttpActionResult and async Task<IHttpActionResult> is whether any of your code utilizes the async and await feature. Many libraries like Entity Framework

Creating new IHttpActionResult action result methods

断了今生、忘了曾经 提交于 2019-12-02 20:09:05
Is there a way I can use the new IHttpActionResult interface to return a HttpStatusCode.NoContent response message? I am currently using return new HttpResponseMessage( HttpStatusCode.NoContent ); and would like to convert this into return NoContent(); . IHttpActionResult has already got Ok() , Conflict() and NotFound() but I cannot find any for Forbidden() and NoContent() which I need to use in my project. How easy is it to add other result types? Rafael Companhoni There's no convenience method for no-content result because, by default, when a action returns void , the response will have the