“HTTP 400 - 错误请求(请求标头太长)”对MVC中的HTTP请求的响应

问题描述 投票:-1回答:1

每当我将项目发布到服务器但我在本地工作正常时,我遇到一些关于HTTP 400的问题 - 错误的请求。每当我清除浏览器cookie时,它可以正常运行一段时间,然后启动相同的错误。据我所知,我的cookie内存超过了最大长度。我无法理解的Microsoft Support to this issue。 N.B:我通过cookie从数据库加载我的菜单。这是我的加载菜单代码:

        HttpContext.Current.Response.Cookies.Add(MenuC1);
        HttpContext.Current.Response.Cookies.Add(MenuC2);
        HttpContext.Current.Response.Cookies.Add(MenuC3);
        HttpContext.Current.Response.Cookies.Add(MenuC4);
        HttpContext.Current.Response.Cookies.Add(MenuC5);

        HttpContext.Current.Response.Cookies.Add(AloneC1);
        HttpContext.Current.Response.Cookies.Add(AloneC2);
        HttpContext.Current.Response.Cookies.Add(AloneC3);
        HttpContext.Current.Response.Cookies.Add(AloneC4);
        HttpContext.Current.Response.Cookies.Add(AloneC5);

        UserID["UserID"] = this.User_User.ID.ToString();
        UserName["UserName"] = this.User_User.UserName;

        HttpContext.Current.Response.Cookies.Add(UserID);
        HttpContext.Current.Response.Cookies.Add(UserName);

布局:

<li class="header"> User Menu </li>
@{
HttpCookie MenuC1 = HttpContext.Current.Request.Cookies["Menu1"];
HttpCookie MenuC2 = HttpContext.Current.Request.Cookies["Menu2"];
HttpCookie MenuC3 = HttpContext.Current.Request.Cookies["Menu3"];
HttpCookie MenuC4 = HttpContext.Current.Request.Cookies["Menu4"];
HttpCookie MenuC5 = HttpContext.Current.Request.Cookies["Menu5"];
string Menu = MenuC1["Menu1"].ToString().ToLower() + MenuC2["Menu2"].ToString().ToLower() + MenuC3["Menu3"].ToString().ToLower() + MenuC4["Menu4"].ToString().ToLower() + MenuC5["Menu5"].ToString().ToLower();
string TopMenu = "", SubMenu = "", Menuitem = "", Method = "";
}

这部分代码会导致此错误或任何其他问题吗?如果这种加载菜单的方法导致错误,那么从数据库加载菜单应该更好的方法。对这个问题的任何建议都是可观的。

asp.net-mvc iis webserver
1个回答
0
投票

我认为HTTP请求的大小是有限制的。当您将数据库加载到cookie时,每次请求都会将数据发送到服务器。

你应该像在Razor或JavaScript中一样创建菜单

© www.soinside.com 2019 - 2024. All rights reserved.