I am having the following code on my Home Controller / Viewmodel class
public class HomeController : SurfaceController {
....
[AllowAnonymous]
public ActionResult LoginIn()
{
var user = new UserDetail() { FirstName = "FirstName", LastName = "LastName" };
UserDetailViewModel model = new UserDetailViewModel() { User = user };
return PartialView("~/Views/Partials/__LoginPartial.cshtml", model);
}
........
}
public class UserDetailViewModel : RenderModel
{
public UserDetailViewModel() : this(new UmbracoHelper(UmbracoContext.Current).TypedContent(UmbracoContext.Current.PageId)) { }
public UserDetailViewModel(IPublishedContent content, CultureInfo culture) : base(content, culture) { }
public UserDetailViewModel(IPublishedContent content) : base(content) { }
public UserDetail User { get; set; }
}
And following is the ActionExcuteFilter
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public sealed class ActionExcuteFilter : ActionFilterAttribute {
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (HttpContext.Current.Session == null || Convert.ToInt32(HttpContext.Current.Session["UserId"]) ==0)
{
var myAccountPage = uQuery.GetNodesByType("Login").FirstOrDefault();
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary {
{ "action", "LoginIn" },
{ "controller", "Home" }});
}
base.OnActionExecuting(filterContext);
} }
And on Home page have the following link
http://localhost/Products?categoryId=1 Which refer to action of product controller.
So if user get login, and click on link everything works fine. (Means to say getting the value from UmbracoContext and respective pages get rendered )
But when user Click on the link without login trouble starts (get error while fetching the values from UmbracoContext )
So the Execution is:
Product controller is call > ActionExcuteFilter > RedirectToRouteResult > Home Controller >LoginIn Action > UserDetailViewModel > Gives error (getting UmbracoContext.Current as null)
So what I am trying to do is that, when user try to access page ..Product?categoryId=1 without login he should be redirect to login page.
Thanks in advance :)