c# - Url redirection on OnActionExecuting method -
we trying implement non-hosted header accept before *.website.com
in asp.net. since accept subdomain, extended httpcontextbase class add custom method.
public static bool validatehost(this httpcontextbase context) { var domain = context.request.url.host; //add logic check if host valid , subdomain exist in database return false; }
this method validate whether context.url.host
valid host or subdomain exist in database if not redirect request default host website.com
. added line of codes below in our basecontroller
:
protected override void onactionexecuting(actionexecutingcontext filtercontext) { if (!filtercontext.httpcontext.validateurl()) { filtercontext.httpcontext.response.redirect("https://website.com/"); return; } }
it redirects default host whenever returns false
, throws exception: {"server cannot append header after http headers have been sent."}
am missing here or logic incomplete?
try redirectresult
filtercontext.result = new redirectresult("https://website.com");
Comments
Post a Comment