asp.net-web-api

Where is IHttpControllerFactory?

佐手、 提交于 2020-01-03 13:41:16
问题 Microsoft website says there is a IHttpControllerFactory which can be used to generate controllers in custom ways. However, the System.Web.Http DLL referenced from Visual Studio: packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40\System.Web.Http.dll Doesn't have that interface: So where is the interface now? 回答1: It's gone and replaced by a dependency resolver or more specifically the IDependencyResolver interface. Once you write your own dependency resolve you could plug it into the

How to dispose the object created by Unity DI right after the completing the request?

时光怂恿深爱的人放手 提交于 2020-01-03 13:03:03
问题 I want to know if there is a better to way to handle this. I've set up Unity for dependency injection for our project. The project itself is an ASP.NET application that uses Web API. I have the following packages installed. Unity Unity.ASPNet.WebAPI I see no option to close/dispose the DBContext right after fetching the data. My controller public class NinjasController : ApiController { public Ninja Get(int id) { INinjaRepository repository = UnityConfig.Container.Resolve(typeof

How to dispose the object created by Unity DI right after the completing the request?

时光怂恿深爱的人放手 提交于 2020-01-03 13:02:09
问题 I want to know if there is a better to way to handle this. I've set up Unity for dependency injection for our project. The project itself is an ASP.NET application that uses Web API. I have the following packages installed. Unity Unity.ASPNet.WebAPI I see no option to close/dispose the DBContext right after fetching the data. My controller public class NinjasController : ApiController { public Ninja Get(int id) { INinjaRepository repository = UnityConfig.Container.Resolve(typeof

Binding querystring values to a dictionary

风格不统一 提交于 2020-01-03 12:34:49
问题 I'm using Web API (part of ASP.NET MVC 5), and I'm trying to bind querystring values to a Dictionary<int, bool> . My Web API method is simply: [HttpGet] [Route("api/items")] public IQueryable<Item> GetItems(Dictionary<int, bool> cf) { // ... } If I try to invoke this URL: /api/items?cf[1009]=true&cf[1011]=true&cf[1012]=false&cf[1015]=true The parameter cf is always null . How can I pass in a dictionary of values via the QueryString to a Web API method? 回答1: When you want to pass a dictionary

WebAPI call using volley

时光怂恿深爱的人放手 提交于 2020-01-03 11:37:08
问题 I'm trying to get access tokens from the server using a volley String request. I have tried making a JsonObjectRequest also. Both are below. public void getAuthenticationTokens(Object param1, final CustomListener<String> listener) { //String url = prefixURL + "this/request/suffix"; String url = "https://lw.xxx.co.uk/connect/token"; StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { //

AuthorizeAttribute not working on Web Api Controller in Mvc 5 application

吃可爱长大的小学妹 提交于 2020-01-03 11:28:09
问题 I have an MVC 5 application that uses Individual User Accounts as authentication. I add an Web Api2 empty controller to my Controllers folder, and an post action. [Authorize] public class AttendancesController : ApiController { [HttpPost] public IHttpActionResult Attend([FromBody]int Id) { I run the application, i log in and then i use Postman or Fidler to send a post request. I always get response with the Login page of my application. The [Authorize] attribute does not work on my api

How to log which action method is executed in a controller in webapi

。_饼干妹妹 提交于 2020-01-03 08:45:22
问题 In WebAPI, is there anyway to log the name of the action method for a controller that gets called or executed using an action filter. I am using the RouteData property as shown below, but the action value does not contain any value. Is there any way I can get the action name in the filter. public class LogActionFilter : ActionFilterAttribute { public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { Log(actionExecutedContext.ActionContext.RequestContext

C# Web API Sending Body Data in HTTP Post REST Client

a 夏天 提交于 2020-01-03 08:32:07
问题 I need to send this HTTP Post Request: POST https://webapi.com/baseurl/login Content-Type: application/json {"Password":"password", "AppVersion":"1", "AppComments":"", "UserName":"username", "AppKey":"dakey" } It works great in RestClient and PostMan just like above. I need to have this pro-grammatically and am not sure if to use WebClient, HTTPRequest or WebRequest to accomplish this. The problem is how to format the Body Content and send it above with the request. Here is where I am with

Failed to add reference to 'System.Net.Http'. Please make sure that it is in the Global Assembly Cache

☆樱花仙子☆ 提交于 2020-01-03 06:44:09
问题 I am trying to add Microsoft.AspNet.WebApi Nuget Package to a C# Class Library Project. Here's the Project source code in case you need it. When I execute the following command in the Nuget Package Manager Console in Visual Studio 2013 (it has latest .NET 4.5 in it) PM> install-package Microsoft.AspNet.WebApi ErrandBoy.Web.Common I get the following Error. PM> install-package Microsoft.AspNet.WebApi ErrandBoy.Web.Common Attempting to resolve dependency 'Microsoft.AspNet.WebApi.WebHost (≥ 5.2

Work with Web API and Windows Phone

ε祈祈猫儿з 提交于 2020-01-03 06:21:21
问题 I am developing a solution that is composed of two elements: a web server, which publishes some REST services, and a mobile client, which consumes those services. To implement the REST services I have used the Web API technology. When I start the web project in debug, everything works fine. I can use the services by pointing to localhost:63954/api. A weird fact: if I change "localhost" with "127.0.0.1" or with the LAN address of the machine, 192.168.xxx.xxx, the server does not answer anymore