I used the identity to assign roles to users.now I want to redirect users according to their role to certain pages.for example user with role"user" after login redirects to a page saus hello user.different from that of admin.I have created the pages and
validate authorization each .but where should I redirect after login?
Hi,
Here my project for your reference:
<!DOCTYPE html> <html ng-app="app" ng-controller="appController as am"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>@ViewBag.Title -{{am.title}}</title> @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") <link rel="icon" href="@Url.Content("~/Content/images/Jacobs.ico")" /> </head> <body> <div class="navbar navbar-inverse navbar-fixed-top" ng-controller="headerController as hm"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <img src="~/Content/images/JacobS0.png" class="navbar-brand" style="padding:5px;" /> @Html.ActionLink("{{hm.title}}", "Index", "Home", null, new { @class = "navbar-brand" }) </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li>@Html.ActionLink("Home", "Index", "Home")</li> <li>@Html.ActionLink("About", "About", "Home")</li> <li>@Html.ActionLink("Contact", "Contact", "Home")</li> @if (Request.IsAuthenticated && User.IsInRole("Admin")) { <li>@Html.ActionLink("RolesAdmin", "Index", "RolesAdmin")</li> <li>@Html.ActionLink("UsersAdmin", "Index", "UsersAdmin")</li> } </ul> @Html.Partial("_LoginPartial") </div> </div> </div> <div class="container body-content"> @RenderBody() <hr /> <footer ng-controller="footerController as fm"> <p>© @DateTime.Now.Year - {{fm.title}} {{fm.subTitle}}</p> </footer> </div> @Scripts.Render("~/bundles/jquery") <script src="~/Scripts/angular.min.js"></script> <script src="~/Scripts/angular-animate.min.js"></script> <script src="~/Scripts/angular-route.min.js"></script> <script src="~/Scripts/angular-sanitize.min.js"></script> @Scripts.Render("~/bundles/bootstrap") @Scripts.Render("~/bundles/app") @RenderSection("scripts", required: false) </body> </html>
Look at this part, it’s bold at the previous code:
@if (Request.IsAuthenticated && User.IsInRole("Admin")) { <li>@Html.ActionLink("RolesAdmin", "Index", "RolesAdmin")</li> <li>@Html.ActionLink("UsersAdmin", "Index", "UsersAdmin")</li> }
Have fun