c# - How to set ActionExecutingContext status code -
i using localization actionfilterattribute , working fine, except need redirect /
/en
status code of 301
instead of 302
. how can fix this?
code
public class localize : actionfilterattribute { public override void onactionexecuting(actionexecutingcontext filtercontext) { // .. irrelevent logic here .. // set redirect code 301 filtercontext.httpcontext.response.status = "301 moved permanently"; filtercontext.httpcontext.response.statuscode = 301; // redirect filtercontext.result = new redirectresult("/" + cookielanguage); base.onactionexecuting(filtercontext); } }
proof
redirectresult
has constructor overload takes url , bool indicate if redirect should permanent:
filtercontext.result = new redirectresult("/" + cookielanguage, true);
from can see, should available in mvc 4.
Comments
Post a Comment