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

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -