ASP.NET MVC 3 OnActionExecuting causes infinite loop?

That's probably because the controller action that you are redirecting to (the login url I think) is also decorated with this attribute. So if the user is not authenticated he gets redirected to the login action and because he is not authenticated he gets redirected to the login action and so on. Personally I would recommend you using the Authorize attribute instead of writing such action filter.

Up vote 0 down vote favorite share g+ share fb share tw.

I have that overriden OnActionExecuting method (to check before action execute if user is logged in) public class AuthenticationAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { if (!filterContext.HttpContext.User.Identity. IsAuthenticated) { string redirectUrl = string. Format("?

ReturnUrl={0}", filterContext.HttpContext.Request.Url. PathAndQuery); filterContext.HttpContext.Response. Redirect(FormsAuthentication.

LoginUrl + redirectUrl, true); } else base. OnActionExecuting(filterContext); } } Why - if user is not logged in - the response is redirected to that method again. Why?

Asp. Net-mvc-3 onactionexecuting link|improve this question asked May 13 '11 at 9:56Tony1,240727 63% accept rate.

But if I use the Authorize attribute on the Controller the result is a blank page (the URL is changed properly) – Tony May 13 '11 at 10:03 2 @Tony, the authorize attribute will automatically redirect to the login page you defined in the section of your web.config. So ensure that the url that is defined there corresponds to an actual controller action in your application. – Darin Dimitrov May 13 '11 at 10:23.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions