Browsed byCategory: Web

Source Try using a simple HttpResponseMessage with its Content property set to a StreamContent:

C#

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

// using System.IO;

// using System.Net.Http;

// using System.Net.Http.Headers;

publicHttpResponseMessage Post(stringversion,stringenvironment,

stringfiletype)

{

varpath=@"C:\Temp\test.exe";

HttpResponseMessage result=newHttpResponseMessage(HttpStatusCode.OK);

varstream=newFileStream(path,FileMode.Open,FileAccess.Read);

result.Content=newStreamContent(stream);

result.Content.Headers.ContentType=

newMediaTypeHeaderValue("application/octet-stream");

returnresult;

}

A few things to note about the stream used: You must not call stream.Dispose(), since Web API still needs to be able to access it when it processes the controller method’s result to send data back to the client. Therefore, do not use a using (var stream = …) block. Web API will dispose the stream for you. Make sure that the stream has its current position set to 0 (i.e. the beginning of the stream’s data)….

Source This article demonstrates how to call or map Web API methods with different types of parameters using XML, Json and Urlencoded formats. It shows how simple parameters, objects parameters and array parameters can be sent either in the body of the Http request or in the Url itself. This all works per default in Web API and if that’s not enough, you can customize it yourself. code: https://github.com/damienbod/WebApiParameters Simple Parameters Example 1: Sending a simple parameter in the Url 1 2…

Source This afternoon my good friend Pranav Rastogi pointed out that we don’t have a walkthrough showing how to use the On-Premises option for organizational authentication in the new ASP.NET project templates in VS2013 – AKA hooking up your web app to an ADFS instance. You know what? He was right! With all the excitement around the new capabilities for cloud-based project, we didn’t cover this specific feature as that is largely a refactoring of what was already available in the Identity and…