Click here to Skip to main content
15,889,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello i implement a new filter attribute to check if the client side
Allows cookies.

public class CookieActionFilter : System.Web.Mvc.ActionFilterAttribute ,IActionFilter
   {

       public override void OnActionExecuting(ActionExecutingContext context)
       {


           if (!cookiesAreEnabled())
           {
               context.Result = new RedirectResult("/Error");
           }

           base.OnActionExecuting(context);
       }

   }


i have an controller interface for authentication and localization.

public class HomeController : AppController


and my appController i think do the problem ??

this is the override method for the culture localization:
protected override void ExecuteCore()
        {
            int culture = 0;
            if (this.Session == null || this.Session["CurrentCulture"] == null)
            {
                int.TryParse(System.Configuration.ConfigurationManager.AppSettings["Culture"], out culture);
                this.Session["CurrentCulture"] = culture;
            }
            else
            {
                culture = (int)this.Session["CurrentCulture"];
            }
            // calling CultureHelper class properties for setting  
            TORWebApplication.Helper.CultureHelper.CurrentCulture = culture;

            base.ExecuteCore();
        }


the base.ExecuteCore(); throw me


An exception of type 'System.Web.HttpException' occurred in System.Web.Mvc.dll but was not handled in user code

Additional information: Cannot redirect after HTTP headers have been sent.
Posted

1 solution

When processing an HTTP request, there is a certain point when you can not redirect your process to an other page...
RedirectResult[^] does exactly that redirection in the wrong place...
The reason for that error is that all/part of the HTTP headers already written to the output stream, and a redirection - being also a HTTP header line with 'location' in it - conflicts with existing header lines...
You probably have not to call base for OnActionExecuting, if you redirect the action...
 
Share this answer
 
Comments
Member 10631195 15-Mar-15 4:40am    
Thank you for teaching me a few things but I still do not know where to check&redirect
i remove the base call but still this is not the place to redirect ?
where i need to check if the client side
Allows cookies ?
Kornfeld Eliyahu Peter 15-Mar-15 4:44am    
It is definitely not a good place to redirect your flow...
However to advise more I need to understand more your requirements/solution...
Member 10631195 15-Mar-15 4:52am    
I will try to figure out where I can put the redirect call
Kornfeld Eliyahu Peter 15-Mar-15 4:53am    
Try to see if you can do without redirect at all...
Member 10631195 15-Mar-15 5:25am    
I'll think about it thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900