0

i used Rotativa to print one of my page from html to pdf and when i hit the button to print,it will open print preview,but the preview does not contains that page i just print , it contains and show me log in page in preview instead as you can see,so idont know exactly whats happend.Can someone please point me in the right direction?

The page i tried to print look like this: enter image description here But when i hit the button to print,in preview give me log in page:

enter image description here

AccountController:

protected override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                if (Session["CustomerID"] == null &! Request.RawUrl.ToLower().Contains("login"))
                {
                     Response.Redirect("/Account/Login");
                }
                base.OnActionExecuting(filterContext);
            }

<br>
 //Login


public ActionResult Login()
    {

        return View();

    }
    [HttpPost]
    public ActionResult Login(Customers cust)
    {

        using (DataContext db = new DataContext())
        {
            var user = db.Customers.Where(u => u.CustomerID == cust.CustomerID).FirstOrDefault();

            if (user != null)
            {
                Session["CustomerID"] = user.CustomerID.ToString();
                FormsAuthentication.SetAuthCookie(cust.CustomerID, false);
                Session.Timeout = 30;

                return RedirectToAction("LoggedIn");
            }

            else
            {
                ModelState.AddModelError("", "CustomerID is not Valid");
            }
        }
        return View();

    }

    public ActionResult LoggedIn()
    {

        if (Session["CustomerID"] != null)
        {
            string customerId = Session["CustomerID"].ToString();
            List<Orders> customerOrders;
            using (DataContext data = new DataContext())
            {
                customerOrders = data.Orders.Where(x => x.CustomerID == customerId).ToList();
            }

            return View(customerOrders);
        }
        else
        {
            return RedirectToAction("Login");
        }

    }
    public ActionResult Logout()
    {
        FormsAuthentication.SignOut();
        Session.Remove("Login");
        return RedirectToAction("Login", "Account");
    }

    public ActionResult PrintOrders(int id)
            {
                var report = new ActionAsPdf("ShowOrdersDetails", new { id = id });
                return report;
            }
  • It's pretty obvious that Rotative runs in a different context from the users session.That's why .NET is sending it to the login page.... – Steve Aug 29 '17 at 12:46
  • 1
    See this question : https://stackoverflow.com/questions/35067191/why-does-rotativa-always-generate-my-login-page-why-is-it-slow – Steve Aug 29 '17 at 12:48
  • 1
    Tnx Steve , it was helpful –  Aug 29 '17 at 13:00

0 Answers0