How to add Web API to an existing ASP.NET MVC (5) Web Application project?

Update the MVC project Use Nuget to get the newest Web API. Project – Right click – Manage Nuget Packages – Search for Web API (Microsoft ASP.NET Web API …) and install it to your MVC project. Then you still need to get Web API routing to work. From Microsoft’s Configuring ASP.NET Web API 2 … Read more

API for Performance and Endurance storage(Block storage)

To order Endurance, execute: Configuration: Package to use = 240 Storage Type: Endurance Location: Dal06 Storage Package: 0.25 IOPS/GB Storage Size: 20GB Snapshot Space Size: 0GB OS Type: Linux URL: https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder Method: POST Json Payload: { “parameters”: [ { “location”: 154820, //Dallas 06 “packageId”: 240, “osFormatType”: { “id”: 12, “keyName”: “LINUX” }, “complexType”: “SoftLayer_Container_Product_Order_Network_Storage_Enterprise”, “prices”: … Read more

Passing asp.net server parameters to Angular 2 app

An option would be to add a method in the module you import. So you can then call it to provide the object you want. Here is a sample of the app/main module: import {bootstrap} from ‘…’; import {provide} from ‘…’; import {AppComponent} from ‘…’; export function main(params) { let userIdentityName = params.name; // for … Read more

Is there a default verb applied to a Web API ApiController method?

File this under learning something new every day! Typically method name matching is thought of this way. Looking at the WebAPI source, however, there is a branch of logic for fallback. If the method name doesn’t map (through attribute, or convention) to a supported HTTP verb, then the default is POST. By default action selection … Read more

HTTP PUT not allowed in ASP.NET Web API

Apparently, there is a known problem within AttributeRouting wherein the HttpPut methods are currently non-functional in ASP.NET Web API. The currently accepted workaround is add the appropriate verb onto the route until a proper fix comes along: Web API RC sealed a vital interface for route detection by the underlying framework. Though the interface is … Read more

Web API Queryable – how to apply AutoMapper?

Use the AutoMapper’s Queryable Extensions. First, define the mapping. // Old AutoMapper API // Mapper.CreateMap<Person, PersonDto>(); // Current AutoMapper API Mapper.Initialize(cfg => cfg.CreateMap<Person, PersonDto>() ); Then you can use something like this: [EnableQuery] public IQueryable<PersonDto> Get() { // Old AutoMapper API // return this.dbContext.Persons.Project().To<PersonDto>(); // New AutoMapper API return this.dbContext.Persons.ProjectTo<PersonDto>(); } Edit 04/2019: Updated to … Read more

Get IPrincipal from OAuth Bearer Token in OWIN

I found a part of the solution in this blog post: http://leastprivilege.com/2013/10/31/retrieving-bearer-tokens-from-alternative-locations-in-katanaowin/ So I created my own Provider as follows: public class QueryStringOAuthBearerProvider : OAuthBearerAuthenticationProvider { public override Task RequestToken(OAuthRequestTokenContext context) { var value = context.Request.Query.Get(“access_token”); if (!string.IsNullOrEmpty(value)) { context.Token = value; } return Task.FromResult<object>(null); } } Then I needed to add it to my … Read more

ASP.net MVC4 WebApi route with file-name in it

You could add the following handler to the <handlers> section of your <system.webServer>: <add name=”ManagedDllExtension” path=”api/nav/*/*.dll” verb=”GET” type=”System.Web.Handlers.TransferRequestHandler” preCondition=”integratedMode,runtimeVersionv4.0″ /> This will make all requests containing .dll be served through the managed pipeline. Also notice how I have limited them only to the GET verb to limit the performance impact.