Browsed by
Category: Web

Returning binary file from controller in ASP.NET Web API

Returning binary file from controller in ASP.NET Web API

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

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)….

Read More Read More

ASP.NET MVC – Set custom IIdentity or IPrincipal

ASP.NET MVC – Set custom IIdentity or IPrincipal

Source I decided to use IPrincipal instead of IIdentity because it means I don’t have to implement both IIdentity and IPrincipal. Create the interface

CustomPrincipal

  CustomPrincipalSerializeModel – for serializing custom information into userdata field in FormsAuthenticationTicket object.

  LogIn method – setting up a cookie with custom information

  Global.asax.cs – Reading cookie and replacing HttpContext.User object, this is done by overriding PostAuthenticateRequest

  Access in Razor views

    and in code:…

Read More Read More

WEB API 2 EXPLORING PARAMETER BINDING

WEB API 2 EXPLORING PARAMETER BINDING

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…

Read More Read More

Send string array to web api

Send string array to web api

You can send it in the body or the URL URL:

or in the body:

Here’s example of parameters bindings: http://damienbod.wordpress.com/2014/08/22/web-api-2-exploring-parameter-binding/

Use the On-Premises Organizational Authentication Option (ADFS) With ASP.NET in Visual Studio 2013

Use the On-Premises Organizational Authentication Option (ADFS) With ASP.NET in Visual Studio 2013

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…

Read More Read More