summaryrefslogtreecommitdiffstats
path: root/samples/OAuthAuthorizationServer/Code/HttpHeaderAttribute.cs
blob: d3201c2cf2881fb43ce42bedea011c775c6d3e22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
namespace OAuthAuthorizationServer.Code {
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Web;
	using System.Web.Mvc;

	/// <summary>
	/// Represents an attribute that is used to add HTTP Headers to a Controller Action response.
	/// </summary>
	public class HttpHeaderAttribute : ActionFilterAttribute {
		/// <summary>
		/// Initializes a new instance of the <see cref="HttpHeaderAttribute"/> class.
		/// </summary>
		/// <param name="name">The HTTP header name.</param>
		/// <param name="value">The HTTP header value.</param>
		public HttpHeaderAttribute(string name, string value) {
			this.Name = name;
			this.Value = value;
		}

		/// <summary>
		/// Gets or sets the name of the HTTP Header.
		/// </summary>
		public string Name { get; set; }

		/// <summary>
		/// Gets or sets the value of the HTTP Header.
		/// </summary>
		public string Value { get; set; }

		/// <summary>
		/// Called by the MVC framework after the action result executes.
		/// </summary>
		/// <param name="filterContext">The filter context.</param>
		public override void OnResultExecuted(ResultExecutedContext filterContext) {
			filterContext.HttpContext.Response.AppendHeader(this.Name, this.Value);
			base.OnResultExecuted(filterContext);
		}
	}
}