w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » ASP NET WEB API » Page 1
Multiple actions were found that match the request - WebApi
Ok, thanks for all the help on this. This was fixed by adding config.MapHttpAttributeRoutes(); to the WebApiConfig. I removed the default route definitions since I am going to use AttributeRouting and it's working now. update: It looks like it is possible to mix Attribute and Convention routing in the WebApiConfig as discussed here So my problem was solved by adding config.MapHttpAttributeR

Categories : Asp Net Web Api

How to setup jwplayer with web api?
Use this, and it will work: jwplayer("myElement").setup({ //file: "big_buck_bunny.mp4", file: "http://localhost:52272/api/donwloadfile/1", primary: 'flash', type: 'mp4' });

Categories : Asp Net Web Api

Identity disappears from bearer token after an hour
you seem to be crossing flows here. If you are making calls from JavaScript, you should obtain the token in the client - something like http://www.cloudidentity.com/blog/2014/10/28/adal-javascript-and-angularjs-deep-dive/. Redirect based authentication flows in which the outcome is a cookie are not well suited for scenarios in which you call API via JavaScript. Furthermore, if I understood correct

Categories : Asp Net Web Api

asp.net web api self hosting / owin / katana
NuGet package here clearly states this. Microsoft ASP.NET Web API 2.2 Self Host 5.2.2 This is a legacy package for hosting ASP.NET Web API within your own process (outside of IIS). Please use the Microsoft.AspNet.WebApi.OwinSelfHost package for new projects. Anyways, SelfHost is old and is based on WCF stack. OwinSelfHost is new and is based on Katana (name is Katana and not Kitana, BT

Categories : Asp Net Web Api

WebApi response codes
You should return NotFound (404), because the url is valid but the required resource doesn't exists. check this.

Categories : Asp Net Web Api

ExceptionFilterAttribute for ApiController is being ignored
1- Make sure that you don't have any catch anywhere in the pipeline that handle the exceptions and swallows them. 2- You don't need to decorate your action by HandleExceptionsAttribute if you added the filter globally, so remove it and let your code generate en exception and see what happens, Looking at your code, I believe everything setup correctly and it should work.

Categories : Asp Net Web Api

System.Web.Http.GlobalConfiguration does not contain a definition for 'Configure
After hours of investigating i have found out that after I have installed ASP.NET Web API 2.2, the reference path of all dlls was from some old Web API - it didn't take the new ones. The new dlls has been installed in packages folder, while the old one were in bin folder inside project.

Categories : Asp Net Web Api

WinRT use HttpClient to call Web API based URL with token
Your Capabilities are enough. You don't even need Internet (Client) because it's included in Internet (Client & Server). You do not have credentials for WinRT HttpClient, in your linked post they referr to System.Net.Http.HttpClientHandler. Maybe you can use the HttpBaseProtocolFilter to add the credentials? using (var httpFilter = new HttpBaseProtocolFilter()) { using (var httpClient =

Categories : Asp Net Web Api

Routing with Web API
Check this link: http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api Look at the section "Routing By Action Name".

Categories : Asp Net Web Api

WebAPI - config.EnableQueryOptions is marked as depreciated what is the gudance now?
If you are referring to this nugget package Microsoft.AspNet.Odata Then sample code could look like this public static void Register(HttpConfiguration config) { // New code: ODataModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet<Product>("Products"); config.MapODataServiceRoute( routeName: "ODataRoute", routePrefix: null, mo

Categories : Asp Net Web Api

Can I modify response content before the formatter processes it?
Have You tried using an ActionFilterAttribute where you can override the OnActionExecuting/OnActionExecuted methods to process/generate the action response using the actionContext. Have a look into this good article. Also look at this question. Hope that helps.

Categories : Asp Net Web Api

Using ActionName attribute seems to break Swagger documentation (Web API, Swashbuckle)
I've determined this is a bug in Swashbuckle. .NET generates the XML documentation with the actual method name, not the name specified in the ActionName attribute. Therefore, it needs to be handled in the Swashbuckle code. I've entered an issue in GitHub, including a workaround until it is fixed -- https://github.com/domaindrivendev/Swashbuckle/issues/118.

Categories : Asp Net Web Api

Url.Link(): Route cannot be found when using attribute routing
You need to name your route like this: [Route("api/companies/{companyId:Guid}", Name="MyRouteName")] and then use Url.Link("MyRouteName", new { companyId = company.Id })

Categories : Asp Net Web Api

Web.Api defining optional parameters in route
This is the solution: [Route("customers/{customerId}/boats/{boatId}/bookings", Name = "GetBookingsByBoat")] [ResponseType(typeof (IEnumerable<BookingSummaryDTO>))] public IHttpActionResult Get(int customerId, int boatId, int? contractId = null, DateTime? startDate = null, DateTime? endDate = null, bool outOnly = false)

Categories : Asp Net Web Api

How to retrieve all requested params in .NET Web API 2?
public HttpResponseMessage Post(HttpRequestMessage req) { var content = req.Content.ReadAsStringAsync().Result; return null; } Also note that the request body is a non-rewindable stream; it can be read only once, you can't call ReadAsStringAsync() multiple times.

Categories : Asp Net Web Api

How to override a web api route?
I have pretty much the same problem. I am creating a starter site, but I want users to be able to redefine to behaviour of a Controller, especially if there is a bug. I use Autofac to resolve the Controller, but even when I register the new controller as the old one, the original one gets selected. What I'll do is probably go with URL Rewriting. Especially since this issue is temporary in my c

Categories : Asp Net Web Api

Resource Description on Web API Help page is showing "None."
(This probably ought to be a comment but I don't have enough rep yet) I'd start with break pointing the various points in AreasHelpPage - e.g. XmlDocumentationProvider - to see if that gives you any clues. Nothing leaps out at me. Could it be that you've changed where the XML help file is output and not updated the document path passed to XmlDocumentationProvider? The path is set through the Pr

Categories : Asp Net Web Api

ASP.Net Web API POST to table with just a single identity column
Found out a way to get around this. Pretty much have the codes as below: // POST: api/XXXX [ResponseType(typeof(MyFileDTO))] public IHttpActionResult PostMyFile(MyFile myFile) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.MyFile.Add(myFile); db.SaveChanges(); // Get the highest myFile value. long maxMyFileId = db.MyFile.Max(p => p.MyFileId)

Categories : Asp Net Web Api

WebAPI call brings in the xml namespace that causes the deserialization to fail
Try annotating your GetStudentStatus class with the DataContract attribute but specify the Namespace property so that it includes the namespace where the class is located. [DataContract(Name = "GetStudentStatus", Namespace = "http://schemas.datacontract.org/2004/07/[NameSpace]")] public class GetStudentStatus { public string StudentID { get; set; } public string Batch { get; set; } }

Categories : Asp Net Web Api

Web Api OData v3 - Cast or IsOf Function must have a type in its arguments
You need to pass the type with single quotes, like this: http://localhost:50050/odata/Store?$inlinecount=allpages&$top=20&$filter=isof('MyNamespace.Data.Core.Entities.Engineer')&$orderby=Name%20asc When you do that though, you will get the following exception: System.NotImplementedException: Unknown function 'isof'. at System.Web.Http.OData.Query.Expressions.FilterBinder.BindSin

Categories : Asp Net Web Api

Web API help page
The Help page is created in the folder called "Areas". Inside the file HelpPageAreaRegistration.cs there is a route defined such as the following - context.MapRoute( "HelpPage_Default", "api/Help/{action}/{apiId}", new { controller = "Help", action = "Index", apiId = UrlParameter.Optional }); This tells how to navigate to the help page. The defin

Categories : Asp Net Web Api

Web API Parameter Binding
At last, Added Custom Model binder public class PostParameterModelBinder : IModelBinder { bool IModelBinder.BindModel(System.Web.Http.Controllers.HttpActionContext actionContext, ModelBindingContext bindingContext) { bool success = false; if (bindingContext.ModelType == typeof(ClientRequest)) { NameValueCollection postData = null; pos

Categories : Asp Net Web Api

Why Microsoft.Owin.Host.SystemWeb failed to install?
Try changing <package id="Microsoft.Owin.Host.SystemWeb" version="3.0.0" targetFramework="net45" /> to <package id="Microsoft.Owin.Host.SystemWeb" version="3.0.0" targetFramework="net452" />

Categories : Asp Net Web Api

Why am I getting this ActivationException when using Simple Injector with WebApi Self Hosted in OWIN?
It turned out that the exception only bubbles up when I have the Common Language Runtime Exceptions checked to thrown When I untick the checkbox everything behaves as normal! which is weird! also wrapping it in a Try-Catch (Exception) doesn't even catch it which makes it even more interesting/werid!

Categories : Asp Net Web Api

Making a Web API method accept an xml
Try this in the controller code...Remove Get Prefix, no need to add [HttpPost] Put a breakpint to see if it hits there. public void PostStudent(string studentXml) { //Write your logic here } Try this in the code from where you are posting data using (var client = new WebClient()) { var data = "XML data" //Try HTML.Encode if it does not work var result = client.Upl

Categories : Asp Net Web Api

MSBuild Web API project not creating a deployable package
I read around and saw that I might have to add the property VisualStudioVersion, but whenever I tried it the package still failed. I was just comparing the csproj files and noticed that the following property group was missing: <PropertyGroup> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> <VSToolsPath Condition="'$(VSToolsPath

Categories : Asp Net Web Api

Validate Thinktecture OAuth Token in web api
Old question - I hope you figured out the answer? You need to add the token as a bearer token to the client calling the web api. From a .Net client it would be something like this (where "token" would be "result" from your call to RequestResourceOwnerPasswordAsync): var client = new HttpClient(); client.SetBearerToken(token); var response = client.GetStringAsync(<yourUrl>).Result; In

Categories : Asp Net Web Api

Asp.net Web Api NuGet Packages
In short, no you don't. When you choose the Web Api template in VS it assumes a lot of the packages (and folders) you will need. I usually start with an empty asp.net application and just use NuGet to add the packages I need. This is what mine looks like: <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Microsoft.AspNet.Cors" version="5.2.2" targetFramework="net4

Categories : Asp Net Web Api

Web Api Controller Authorize - where are these roles defined?
In the database. Asuming you're using ASP.NET Identity 2.0, it will create a database schema for you (by default using LocalDB, but you can point the connection string to SQL Server Express if you look). It comes with a Roles table. You can then attach this role to the user. Since you seem to be looking for some kind of admin interface, check out ThinkTecture IdentityManager by Brock Allen. I'm n

Categories : Asp Net Web Api

Autofac, Owin, Webapi and injecting to AuthorizationServerProvider
When you register an instance of an object rather than a type, even if you specify PropertiesAutowired that will not take effect because Autofac assumes you've done all the work you want when you create the instance. If you want properties wired in, you need to do that in an OnActivated handler. There are actually a lot of things at play in this sample code that will not work. The values in Sim

Categories : Asp Net Web Api

.NET Web Api Logging Response Body
Try changing the handler to use async/await instead: protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { var response = await base.SendAsync(request, cancellationToken); await LogResponseLoggingInfo(response); return response; } private async Task Log

Categories : Asp Net Web Api

Using Autofac's resolver on demand in WebAPI perRequest to handle Circular errors
You can't just begin a lifetime scope in Web API. The request lifetime scope is carted around with the request message. By manually creating a request lifetime scope like this, you're not going to get the results you are looking for - especially if you have per-request lifetime scope dependencies, because the scope you're creating will not be the same scope as the actual request lifetime. You won'

Categories : Asp Net Web Api

Calling Web API from an aspx page is always resulting in Not Found error
I found the answer after a lot of trying. This will be very useful in cases when using jQuery from an aspx page to call Web API in webforms asp.net projects, since in such projects the pages will exist under different folders. Only a simple change is needed so the Web API can be called seamlessly from an aspx page under folder 'Vendors' using the url: 'api/AppsProcureWebApi'. This simple change

Categories : Asp Net Web Api

Breeze batch request with ODataConventionModelBuilder
It seems like this error was introduced sometimes between version 5.2.2 and 5.3.1 in the Microsoft.AspNet.WebApi.OData and BreezeJS is not adopted yet accordingly: OData issue after updating to Microsoft.AspNet.WebApi.OData 5.3.x I've added an issue for BreezeJS: https://github.com/Breeze/breeze.js/issues/42

Categories : Asp Net Web Api

How to send Timespan to WebAPI from Javascript
Calculate the duration as described in this answer Get the time difference between two datetimes Define an endpoint like this: public IHttpActionResult Post([FromBody] TimeSpan ts) { // do stuff return Ok(ts); } And post the duration like so: POST http://localhost/theendpoint HTTP/1.1 Content-Length: 12 Content-Type: application/json Host: localhost "00:01:10" A

Categories : Asp Net Web Api

Using the apicontroller to return odata.$count
You can get count separately and put it in new dictionary together with data, returning this dictionary in the method of your controller. The following code applies all that was specified in OData query (including select, expand and filter) and returns both data and count: public class ProductsController : ApiController { public IHttpActionResult Get(ODataQueryOptions<Product> query

Categories : Asp Net Web Api

How to log which action method is executed in a controller in webapi
You can find the action name in the actionExecutedContext.ActionContext.ActionDescriptor.ActionName property (string). You can also cast that ActionDescriptor to ReflectedHttpActionDescriptor and obtain an instance of the MethodInfo that was called, if you need more information than just string name. var reflectedActionDescriptor = actionExecutedContext.ActionContext.ActionDescriptor as

Categories : Asp Net Web Api

Restructuring existing Web API - should I use OAuth?
Does OAuth fit in this scenario where no particular owner exists? Yes it does. Sure, the primary focus of the OAuth specification is to protect resoures owned by the resource owner, but it can of course protect other resources too. Take Facebook for example: it protects not only your data, but also the data of your friends, which is accessible by you. In your case, you need to protect thos

Categories : Asp Net Web Api

CRM Dynamics Web API - Get Quotes
If your code retrieves the Id of the Quote (meaning the unique GUID) probably currently it does something like: Entity quote = service.Retrieve("quote", quoteId, new ColumnSet(true); If you need to retrieve using another field you need to use a QueryExpression in combination with a RetrieveMultiple, something like: QueryExpression query = new QueryExpression("quote"); query.ColumnSet = new Co

Categories : Asp Net Web Api




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.