Note that there are some explanatory texts on larger screens.

plurals
  1. POChange default ASP MVC Request Header to add your own values
    primarykey
    data
    text
    <p>Im trying to change all my ASP MVC HTTP response headers to have another value by default for implementing Pingback auto-discovery in my blog application.</p> <p>The default header (on Cassini) is :</p> <pre><code>Cache-Control private Connection Close Content-Length 20901 Content-Type text/html; charset=utf-8 Date Fri, 20 Apr 2012 22:46:11 GMT Server ASP.NET Development Server/10.0.0.0 X-AspNet-Version 4.0.30319 X-AspNetMvc-Version 3.0 </code></pre> <p>and i want an extra value added : </p> <pre><code>X-Pingback: http://localhost:4912/pingback/xmlrpcserver </code></pre> <p>I have googled a bit and found a neet solution : -- to derive from <strong>ActionFilterAttribute</strong> and override the <strong>OnResultExecuted</strong> method:</p> <pre><code>public class HttpHeaderAttribute : ActionFilterAttribute { public string Name { get; set; } public string Value { get; set; } public HttpHeaderAttribute(string name, string value) { Name = name; Value = value; } public override void OnResultExecuted(ResultExecutedContext filterContext) { filterContext.HttpContext.Request.Headers.Add(Name, Value); base.OnResultExecuted(filterContext); } } </code></pre> <p>And then simply i put the attribute on my Controllers methods:</p> <pre><code>[HttpHeader("X-Pingback","http://localhost:4912/pingback/xmlrpcserver")] public ActionResult Index() { var allArticles = _repository.GetPublishedArticles(SortOrder.desc); return View(allArticles); } </code></pre> <p>When i runt the app i get the following error : <img src="https://i.stack.imgur.com/mhIor.jpg" alt="enter image description here"></p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload