当使用经过身份验证的用户访问授权操作时,asp.net mvc 5是否重定向到登录页面?

时间:2018-01-19 06:07:46

标签: c# asp.net .net asp.net-mvc

我有Authenticated和Guest User都可以访问的操作。所以我将我的控制器和操作标记为

namespace FlightManagementV1.Controllers
{
    [Authorize]
    public class SearchFlightGuestController : Controller
    {
        // GET: SearchFlightGuest
        [AllowAnonymous]
        public ActionResult SearchFlightGuest()
        {
            return View();
        }

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult SearchFlightGuest1(FlightScheduleModel obj)
        {
            CustomerHelper helper = new CustomerHelper();
            List<FlightScheduleModel> list = helper.SearchFlightGuest(obj);
            if (list.Count == 0)
            {
                TempData["ErrorMessage"] = "Sorry!!! We are unable to find any matching Flight for you.";
                return RedirectToAction("SearchFlightGuest", "SearchFlightGuest");
            }
            return View(list);
        }
    }
}

视图SearchFlightGuest1有一个重定向到[Authorize]属性标记的操作的链接。如果访客用户链接自动重定向到登录页面,但对于经过身份验证的用户,该链接也会重定向到登录页面,而不会访问标记为[Authorize]属性的操作。

查看SearchFlightGuest1

<h3>We have found following flights for you</h3>

<br />
<table border="1" style="background-color : white; font-weight : normal">
    <tr>
        <th>
            @Html.Label("Flight ID")
        </th>
        <th>
            @Html.Label("Departure Place")
        </th>
        <th>
            @Html.Label("Destination Place")
        </th>
        <th>
            @Html.Label("Departure Date and Time")
        </th>
        <th>
            @Html.Label("Arrival Date and Time")
        </th>
        <th>
            @Html.Label("Premium Fare (Rs)")
        </th>
        <th>
            @Html.Label("First Fare (Rs)")
        </th>
        <th>
            @Html.Label("Economy Fare (Rs)")
        </th>
        <th>
            @Html.Label("Available (Premium)")
        </th>
        <th>
            @Html.Label("Available (First)")
        </th>
        <th>
            @Html.Label("Available (Economy)")
        </th>
        <th>
            @Html.Label("Distance (KM)")
        </th>
            <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.FlightId)
        </td>
        <td class="field">
            @Html.DisplayFor(modelItem => item.DepPlace)
        </td>
        <td class="field">
            @Html.DisplayFor(modelItem => item.DestPlace)
        </td>
        <td class="field-datetime">
            @Html.DisplayFor(modelItem => item.DepartureDT)
        </td>
        <td class="field-datetime">
            @Html.DisplayFor(modelItem => item.ArrivalDT)
        </td>
        <td class="field">
            @Html.DisplayFor(modelItem => item.FarePremium)
        </td>
        <td class="field">
            @Html.DisplayFor(modelItem => item.FareFirst)
        </td>
        <td class="field">
            @Html.DisplayFor(modelItem => item.FareEconomy)
        </td>
        <td class="field">
            @Html.DisplayFor(modelItem => item.AvailablePremium)
        </td>
        <td class="field">
            @Html.DisplayFor(modelItem => item.AvailableFirst)
        </td>
        <td class="field">
            @Html.DisplayFor(modelItem => item.AvailableEconomy)
        </td>
        <td class="field">
            @Html.DisplayFor(modelItem => item.Distance)
        </td>
        <td>
            @Html.ActionLink("Book Journey", "BookingDetails", "BookJourney", item, new { })
        </td>
    </tr>
}

</table>

我正在尝试访问

的操作
    public class BookJourneyController : Controller
    {
        // GET: BookFlight
        [Authorize]
        public ActionResult BookingDetails(FlightScheduleModel schedule)
        {
            FlightJourneyViewModel journeyViewModel = new FlightJourneyViewModel();
            journeyViewModel.flightSchedule = schedule;
            Session["flight_id"] = schedule.FlightId;
            return View(journeyViewModel);
        }
}

0 个答案:

没有答案