0

So, I've got an Admin Controller that uses the [Authorize] notation with a single admin account (for content management purposes). If the administrator is not logged on, it redirects the user to the login view.

In the Admin controller, I've this ActionResult:

public ActionResult GeneratePDF(int? id) {
    return new ActionAsPdf("PrintOrder/" + id) {
        FileName = Server.MapPath("~/PDF/test.pdf")
    };
}

The above code is currently for testing purposes and will be modified later.

However, when I call the ActionResult from a View (beeing logged on as admin), it only generates a PDF of the Login View as if there is no valid admin session and the user gets redirected. The code works when using the [AllowAnonymous] notation on the PrintOrder ActionResult, but not when a valid user session is required.

Any ideas on how to let the ActionAsPdf method access the required PrintOrder method and still be secured by the [Authorize] notation?

I'm calling the Action from a View as follows:

<a href="@Url.Action("GeneratePDF", "Admin", new { id = item.ID })">Get PDF</a>
Hackerman
  • 12,139
  • 2
  • 34
  • 45

1 Answers1

0

After doing some lengthly research I've found another post with the same issue.

Why does Rotativa always generate my login page? Why is it slow?

The author suggests that the Rotativa code is placed in the same method that it needs access to as a solution. This seems to work as a workaround to the issue and is sufficient for now. However, while a more robust solution would be desired, this will have to do.