Hi,
I have a page with a graph on, for instance, but I do not want to render it when the current user is not authorized. At the moment, when it loads, it renders the partial view, but seems to work when I try and enter date range when doing ajax post.
But initial view I do not want to display…
I hope it makes sense.
Thanks
At the top of the action put
public ActionResult MyAction() { if (userNotAuthorised && !Request.IsAjaxRequest()) // replace with whatever code you need to determine the user is not authorised { return new EmptyResult(); } // rest of action as normal }
AidyF
At the top of the action put
public ActionResult MyAction() { if (userNotAuthorised && !Request.IsAjaxRequest()) // replace with whatever code you need to determine the user is not authorised { return new EmptyResult(); } // rest of action as normal }
Is there not a way to use the Authorize action filter? I tried putting it on class level of the controller that renders the partial view, but 1st run still renders it…
[Authorize(Users = "user", Roles = "Admin")] public class ChartController : Controller {
Then this method
public PartialViewResult LeadChart() { return PartialView(chart); }
thanks
You could condition the section on the view it self as shown below.
@if (User.Identity.IsAuthenticated) { <p> I will only be shown if the user has logged in</p> } else{ <p> You need to login </p> }
Hope it helps.
Hi Kobiewolke,
Thanks for your post.
You can try this in the view:
@{ @if (User.IsInRole("Admin")) { //do something stuff } }
Hope this can be helpful.
Best Regards,
Eileen
Hi thanks for the posts,
I think both will work, I must just go figure out where these users are setup etc.
Thanks will mark both as answers
Regards
Kobie