首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在HTTPS上设置站点后,不允许子操作执行重定向操作。

在HTTPS上设置站点后,不允许子操作执行重定向操作。
EN

Stack Overflow用户
提问于 2014-07-29 12:54:56
回答 3查看 57.3K关注 0票数 21

我得到的错误如下:

代码语言:javascript
运行
复制
Child actions are not allowed to perform redirect actions.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Child actions are not allowed to perform redirect actions.

Source Error:

    Line 1:  <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<RenderActionViewModel>" %>
    Line 2:  <%Html.RenderAction(Model.ActionName, Model.ControllerName, Model.RouteValues); %>
    Line 3: 



The Stack trace is:

    [InvalidOperationException: Child actions are not allowed to perform redirect actions.]


    System.Web.Mvc.RedirectResult.ExecuteResult(ControllerContext context) +700064
       System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +727764
       System.Web.Mvc.Controller.ExecuteCore() +159
       System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +334
       System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
       System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +15
       System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +52
       System.Web.Mvc.<>c__DisplayClass4.<Wrap>b__3() +15
       System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +41
       System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1411

    [HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]
       System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +2819
       System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +275
       System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +94
       System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +828
       System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) +56
       ASP.views_shared_renderaction_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\TFS\PEEP\Src\Main\Hosts\BCA.PEEP.WebSite\Views\Shared\RenderAction.ascx:2
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +12742749
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +249
       System.Web.UI.Page.Render(HtmlTextWriter writer) +40
       System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +65
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +12742749
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5363

我在第2行获得错误的RenderAction.ascx代码是:

代码语言:javascript
运行
复制
    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<RenderActionViewModel>" %>
    <%Html.RenderAction(Model.ActionName, Model.ControllerName, Model.RouteValues); %>

主计长的行动是:

代码语言:javascript
运行
复制
public ViewResult DashboardQuicksearch(UserFilter userFilter, bool? showAdvancedSearchLink)
        {
            int resultCount;
            List<KeyInfo<string>> makeList = quickSearchProvider.GetKeysForCriteriaKey(SearchType.Vehicle, "MakeName", userFilter, "null", false, null, out resultCount);

            var selectListItems = new List<SelectListItem>();
            foreach (KeyInfo<string> item in makeList)
            {
                selectListItems.Add(new SelectListItem() { Text = item.Key, Value = item.Key, Selected = false });
            }

            var viewModel = new DashboardQuicksearchViewModel() {
                MakeList = (makeList.Count == 1)
                    ? new SelectList(selectListItems, "Value", "Text", selectListItems[0].Value)
                    : new SelectList(selectListItems, "Value", "Text"),
                VehicleCount = quickSearchProvider.GetLotItemCount("null", userFilter),
                ShowAdvancedSearchLink = (showAdvancedSearchLink.HasValue ? showAdvancedSearchLink.Value : false)
            };

            return View(Constants.Views.Search.DashboardQuicksearch, viewModel);
        }

我完全不知道怎么修好它。

编辑:

这是DashboardQuickSearch.ascx

代码语言:javascript
运行
复制
<%@ Control Language="C#" Inherits="BCA.PEEP.Web.UI.ViewUserControlBase<DashboardQuicksearchViewModel>" %>
<%@ Import Namespace="BCA.PEEP.Web.Mvc" %>


<div class="Makes">
<%:(Model.MakeList.Count() == 1 
    ? Html.DropDownList("Makes", Model.MakeList, new {@class="search-select"})
    : Html.DropDownList("Makes", Model.MakeList, Html.Text("Name of search results filter:SelectMake"), new {@class="search-select"})
    ) %>
</div>
<div class="Models"><%:Html.DropDownList("Models", new List<SelectListItem>(), Html.Text("Name of search results filter:SelectModel"), new { disabled = "disabled", @class="search-select"})%></div>
<div class="ResultAndAction">
    <span id="VehicleCount" class="VehicleCount"><span class="count-number"><%:Model.VehicleCount.ToString("N0") %></span> <%: Html.Text(Model.VehicleCount, "SearchResultsLabels:Vehicles singular", "SearchResultsLabels:Vehicles plural")%></span>
    <div id="QSButtonDiv" class="Button">
        <input id="QSButton" type="button" value ="<%:Html.Text("Text on buttons:search")%>" onclick="ExecuteSearch()" disabled="disabled" />
    </div>
<% if (Model.ShowAdvancedSearchLink) { %>
    <div id="ASButtonDiv" class="Button Hidden">
        <input id="ASButton" type="button" value ="<%:Html.Text("Text on links:AdvancedSearch")%>" onclick="AdvancedSearch()" />
    </div>
<% } %>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        var vehiclesSingular = '<%=Html.Text("SearchResultsLabels:Vehicles singular")%>';
        var vehiclesPlural = '<%=Html.Text("SearchResultsLabels:Vehicles plural")%>';
        var makeCount = '<%=Model.MakeList.Count().ToString("N0") %>';

        $('#Makes').change(function () { PopulateModels(); });
        $('#Models').change(function () { UpdateVehicleCount(); });
        $('#Makes').trigger('change');

        function PopulateModels() {
            var make = $('#Makes').val();
            var $models = $('#Models');
            $models.append('<option value="" selected>' + '<%=Html.Text("Name of search results filter:SelectModel") %>' + '</option>');
            //alert("Populate Models - Make = '" + make + "'");
            if (make == '') {
                $models.attr('disabled', 'disabled');
                $models.find('option').remove();
                $models.append('<option value="" selected>' + '<%=Html.Text("Name of search results filter:SelectModel") %>' + '</option>');
                $models.val('');
                UpdateVehicleCount();
                $('#QSButton').attr('disabled', 'disabled');
                $('#QSButtonDiv').removeClass('PrimaryButton').addClass('Button');
                return;
            }

            $.ajax({
                type: 'GET',
                url: '/Search/GetModelsForMake/',
                data: { MakeName: make },
                dataType: "json",
                success: function (results) {
                    $models.find('option').remove();
                    $models.append('<option value="" selected>' + '<%=Html.Text("Labels for vehicle characteristics:All Models") %>' + '</option>');
                    $(results.Models).each(function (index, model) {
                        $models.append('<option value="' + model + '">' + model + '</option>');
                    });                    
                    DisplayVehicleCount(results.VehicleCount);
                }
            });
            $models.removeAttr('disabled');
            $('#QSButton').removeAttr('disabled', 'disabled');
            $('#QSButtonDiv').removeClass('Button').addClass('PrimaryButton');
        }

        function UpdateVehicleCount() {
            var make = $('#Makes').val();
            var model = $('#Models').val();

            $.ajax({
                type: 'GET',
                url: '/Search/GetMakeModelCount/',
                data: { MakeName: make, ModelName: model },
                dataType: "json",
                success: function (result) {
                    DisplayVehicleCount(result);
                }
            });
        }

        function DisplayVehicleCount(vehicleCount) {
            var vehicles = (vehicleCount == '1') ? vehiclesSingular : vehiclesPlural;
            $('#VehicleCount').html('<span class="count-number">' + vehicleCount + '</span>' + ' ' + vehicles);
        }

    });

    function ExecuteSearch() {
        var make = $('#Makes').val();
        var model = $('#Models').val();

        if (make == '')
            return;

        window.location = '/Quicksearch/Vehicles?make=' + make + '&model=' + model;
    }

    function AdvancedSearch() {
            <% if(AmbientContextHelper.CurrentBrand.Name.ToLower().Contains("alphabet"))
           { %>
            window.location = '/SearchVehicle';
            <% } else 
           { %>
            window.location = '/Quicksearch/Vehicles';
            <% } %>
        }
</script>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-07-29 13:18:22

这意味着:

  1. 已经处理了与URL对应的操作,并返回了视图结果。
  2. HTML的视图引擎已经开始呈现视图,可能会向浏览器发送头部和部分ASP.NET。
  3. 视图引擎遇到了一个RenderAction(.)调用,并已开始执行该操作。
  4. 此操作试图将HTTP状态代码重定向到浏览器

此时,ASP.NET不知所措:它已经开始向客户端发送头和HTML,但现在突然被告知要收回所有这些,而是发送一个重定向状态代码。它显然无法做到这一点,所以它抛出了一个异常。

您必须弄清楚为什么要触发重定向,并确保不会发生这种情况。最有可能的原因(但绝不是唯一可能的原因)是一些定制的操作过滤器,这些过滤器还没有被设计为考虑到子操作。ASP.NET MVC操作筛选器通常检查执行操作是否作为子操作被调用,并避免在这种情况下重定向。

票数 38
EN

Stack Overflow用户

发布于 2015-09-14 09:55:52

您应该编写return PartialView(...),而不是为childAction编写return View(...)

票数 3
EN

Stack Overflow用户

发布于 2014-07-30 07:23:55

问题是ActionFilter类中的ControllerBase。(我第一次没看到)

就像

代码语言:javascript
运行
复制
[ActionFilters.RequireHttps(RequireSecure = false)]

必须把它设为“真”

谢谢大家的回答。

注意:表示所有动作过滤器属性名称空间的基类: System.Web.Http.Filters程序集: System.Web.Http (在System.Web.Http.dll中)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25015833

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档