ASP.Net MVC: HTTP Error 414. The request URL is too long

I am developing an ASP.Net MVC application. On the button click, I am calling JavaScript function.

this.appDetails = function() {

            editorModel.appModel.application.Name = $("#appTitleText").val();
            editorModel.appModel.application.Nicknames_c = $("#appNicknames").val();
            editorModel.appModel.application.Default_HMI__c = $("#AppModel_application_Default_HMI__c").val();
            editorModel.appModel.application.Description__c = $("#appOverviewText").val();

            $.ajax({
                type: 'POST',
                url: '/Dashboard/Application/AppDetailsEdit',
                data: { 'application': editorModel.appModel },

                success: function (events) {

                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });

        }

Controller.cs

[Authorize]
    [HttpPost]
    public JsonResult AppDetailsEdit(EditAppModel application)
    {
        if (GetUserId() == Guid.Empty)
        {
            throw new UnauthorizedAccessException("Person Not Logged In");
        }
        login();
     }

I get the error

HTTP Error 414. The request URL is too long.

I am getting an error on Ajax call in the javascript function. It looks like URL is not exceeding 2000 char limit. In web.config i am not having maxQueryStringLength.Should I need to set maxUrl in web.config. What do i need to fix this error?


There's really not enough here to properly diagnose your issue. However, given that you're submitting a POST (which doesn't add to the URL) to a static URL string that is not changing (and is well below the limit), it's most likely a result of a redirect loop caused by requiring authorization.

If the user is not logged in, they will be redirected to the login page, but then, if something on the login page, itself, requires authorization, they are redirected again to the login page, which again redirects, etc. Each time it redirects, it affixes a returnUrl param, pointing back to the URL that caused the redirect. With each redirect cycle, this param gets longer and longer until the limit is hit and an exception is raised.

The page that the user is redirected to if they are not authorized should allow anonymous access and anything rendered on that page (child actions) should also allow anonymous access. Check your login action and associated views to see what might be causing the problem.

Also, bear in mind, that when using MVC, even an AJAX call to an action that returns a JsonResult will still redirect to the standard login page for the application, which obviously is useless in the context of an AJAX request. To get around this, you should either use Web Api or don't rely on the Authorize attribute.

To achieve the latter, you still must include the Authorize attribute to have the user data populated in the request, but you should also add AllowAnonymous . Then, in the action, itself, you can check whether the user is actually anonymous or not, and respond accordingly for the purpose of your AJAX request. It looks like you're attempting something like that already, but without AllowAnonymous that code is never utilized.

链接地址: http://www.djcxy.com/p/42030.html

上一篇: maxUrlLength和maxQueryStringLength的更高范围是什么

下一篇: ASP.Net MVC:HTTP错误414.请求URL太长