Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 登录后重定向管理员用户_Asp.net Mvc_Asp.net Identity_Owin - Fatal编程技术网

Asp.net mvc 登录后重定向管理员用户

Asp.net mvc 登录后重定向管理员用户,asp.net-mvc,asp.net-identity,owin,Asp.net Mvc,Asp.net Identity,Owin,我想将管理员用户重定向到管理员控制器中的索引操作。但是当我以管理员身份登录并尝试单击管理员页面链接时,我得到的是“状态404”,无法访问。 我的观点如下: @if (Request.IsAuthenticated) { RidesDbContext context = new RidesDbContext(); UserStore<IdentityUser> userStore = new UserStore<IdentityUser>(context);

我想将管理员用户重定向到管理员控制器中的索引操作。但是当我以管理员身份登录并尝试单击管理员页面链接时,我得到的是“状态404”,无法访问。 我的观点如下:

@if (Request.IsAuthenticated)
{
   RidesDbContext context = new RidesDbContext();
   UserStore<IdentityUser> userStore = new UserStore<IdentityUser>(context);
   UserManager<IdentityUser, string> userManager = new UserManager<IdentityUser, string>(userStore);


   bool exist = userManager.IsInRole(User.Identity.GetUserId(), "Admin");

   if (exist)
   {
           <ul class="nav navbar-nav">
               <li>
                   @Html.ActionLink("Admin Page", "Index", "Admin" , new { @class="nav-link"})
               </li>
        </ul>
   }
}
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutPageDefault.cshtml";
}
<link href="~/Styles/styleHomePage.css" rel="stylesheet" />

<script src="~/Scripts/Animation.js"></script>
<div>
    <h2>RidesApp</h2>


    <div class="mask rgba-gradient d-flex justify-content-center align-items-center">
        <!-- Content -->
        <div class="container">
            <!--Grid row-->
            <div class="row">
                <!--Grid column-->
                <div class="col-md-6 text-white text-center text-md-left mt-xl-5 mb-5 wow fadeInLeft" data-wow-delay="0.3s">
                    <h1 class="h1-responsive font-weight-bold mt-sm-5">Make purchases with our app </h1>
                    <hr class="hr-light">
                    <h6 class="mb-4">
                        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem repellendus quasi fuga nesciunt
                        dolorum nulla magnam veniam sapiente, fugiat! Commodi sequi non animi ea dolor molestiae
                        iste.
                    </h6>
                    <button type="button" class="btn btn-outline-light btn-lg">
                        @Html.ActionLink("Sign up to Drive", "DriversRegistration", "Drivers")
                    </button>
                    <button type="button" class="btn btn-outline-light btn-lg">
                        @Html.ActionLink("Sign up to Ride", "RidersRegistration", "Riders")

                    </button>
                </div>
                <!--Grid column-->
                <!--Grid column-->
                <div class="col-md-6 col-xl-5 mt-xl-5 wow fadeInRight" data-wow-delay="0.3s">
                    <img src="https://mdbootstrap.com/img/Mockups/Transparent/Small/admin-new.png" alt="" class="img-fluid">
                </div>
                <!--Grid column-->
            </div>
            <!--Grid row-->
        </div>
        <!-- Content -->
    </div>
</div>
<!--
我将感谢任何帮助。多谢各位

编辑: 我的索引视图如下所示:

@if (Request.IsAuthenticated)
{
   RidesDbContext context = new RidesDbContext();
   UserStore<IdentityUser> userStore = new UserStore<IdentityUser>(context);
   UserManager<IdentityUser, string> userManager = new UserManager<IdentityUser, string>(userStore);


   bool exist = userManager.IsInRole(User.Identity.GetUserId(), "Admin");

   if (exist)
   {
           <ul class="nav navbar-nav">
               <li>
                   @Html.ActionLink("Admin Page", "Index", "Admin" , new { @class="nav-link"})
               </li>
        </ul>
   }
}
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutPageDefault.cshtml";
}
<link href="~/Styles/styleHomePage.css" rel="stylesheet" />

<script src="~/Scripts/Animation.js"></script>
<div>
    <h2>RidesApp</h2>


    <div class="mask rgba-gradient d-flex justify-content-center align-items-center">
        <!-- Content -->
        <div class="container">
            <!--Grid row-->
            <div class="row">
                <!--Grid column-->
                <div class="col-md-6 text-white text-center text-md-left mt-xl-5 mb-5 wow fadeInLeft" data-wow-delay="0.3s">
                    <h1 class="h1-responsive font-weight-bold mt-sm-5">Make purchases with our app </h1>
                    <hr class="hr-light">
                    <h6 class="mb-4">
                        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem repellendus quasi fuga nesciunt
                        dolorum nulla magnam veniam sapiente, fugiat! Commodi sequi non animi ea dolor molestiae
                        iste.
                    </h6>
                    <button type="button" class="btn btn-outline-light btn-lg">
                        @Html.ActionLink("Sign up to Drive", "DriversRegistration", "Drivers")
                    </button>
                    <button type="button" class="btn btn-outline-light btn-lg">
                        @Html.ActionLink("Sign up to Ride", "RidersRegistration", "Riders")

                    </button>
                </div>
                <!--Grid column-->
                <!--Grid column-->
                <div class="col-md-6 col-xl-5 mt-xl-5 wow fadeInRight" data-wow-delay="0.3s">
                    <img src="https://mdbootstrap.com/img/Mockups/Transparent/Small/admin-new.png" alt="" class="img-fluid">
                </div>
                <!--Grid column-->
            </div>
            <!--Grid row-->
        </div>
        <!-- Content -->
    </div>
</div>
<!--
@{
ViewBag.Title=“Index”;
Layout=“~/Views/Shared/\u LayoutPageDefault.cshtml”;
}
骑乘应用程序
使用我们的应用程序进行购买

Lorem ipsum dolor sit amet,奉献精英。雷姆·杜斯·准福加·奈斯坎特 智慧的大智慧,福吉亚!一般情况下,无动物性或无动物性 伊斯特。 @ActionLink(“注册驾驶”、“驾驶员注册”、“驾驶员”) @ActionLink(“注册骑乘”、“骑乘者注册”、“骑乘者”) 根据,没有与您的参数匹配的重载

试着把它改成

@Html.ActionLink("Admin Page", "Index", "Admin" , new { @class="nav-link"}, new { })

[Authorize]
指任何类型的用户,只要登录即可。如果您被重定向到登录页面,则表示您根本没有登录。除非您的索引视图是登录页面。

您在404页面上得到的URL是什么?默认值/“操作名称”(这是管理控制器中的任何操作),它会将我再次导航到登录页面,即使链接现在存在于导航栏中。@hadeelKh如果您的索引视图只是一个登录表单,那么,即使您已登录,这也是预期的行为。@hadeelKh是否将您的索引视图包括在内?请从
索引
选项中删除
[Authorize]
属性,然后重试。如果页面加载,那么您将知道登录有问题。否则,请检查浏览器中为导航栏管理页面链接生成的超链接。我编辑我的问题,现在它包括我的索引视图。