.NET MVC3 - IIS7上的长POST请求导致404

时间:2012-06-11 21:15:22

标签: .net asp.net-mvc-3

我的表单在MVC3中发布数据时遇到问题。在本地,表单POST成功但在实时服务器上,当有大量的帖子数据时,显示404而不是成功页面。数据来自于包含在POST中的模型,其中通常有很多数据,其中一些是我正在使用的。我已经看过更改web.config中的设置,但这没有帮助。以下是我的代码的一些片段:

观点:

 @using (Html.BeginForm("Bookmarked", "Bookmarklet", Model, FormMethod.Post))
{

<div class="form">
@Html.ValidationSummary(false)

 @Html.TextBoxFor(a => a.Url, new { @class = "hidden" })
 @Html.TextBoxFor(a => a.SelectedImage, new { @class = "selected-image hidden" })

 <div class="form-left">
    <div class="row">
        <label>
            Name:
        </label>
        @Html.TextBoxFor(a => a.Name, new { @class = "textbox" })
        @Html.ValidationMessageFor(a => a.Name, null, new { style = "display:none" })
    </div>

    <div class="row">
        <label>
            Tags:
        </label>
        @Html.TextBoxFor(a => a.Tags, new { @class = "textbox tb-tags", @placeholder = "", onKeyUp = "submitForm(event)" })

    </div>

    <div class="row">
        <br />
        <label>
            &nbsp;</label><a href="javascript:document.forms[0].submit()" class="button fl"><span>Bookmark</span></a>
    </div>
</div>

// The controller

[HttpPost]
    public ActionResult Bookmarked(BookmarkModel initialState, BookmarkModel model)
    {
        try
        {
            HttpCookie cookie = Request.Cookies["UserGuid"];
            HttpCookie cookie2 = Request.Cookies["Username"];
            if (cookie != null && cookie2 != null)
            {
               //do stuff with model data received from the View that the POST comes from

               da.Save(model.Name, cookie.Value);
                return View();
             }
              else
                    throw new Exception("Error saving, please try again");

        }
        catch (Exception ex)
        {
            ModelState.AddModelError("", ex.Message);
            return Bookmark(model);
        }

    }

// web.config

 <system.web>
 <httpRuntime maxUrlLength="10999" maxQueryStringLength="2097151" />
 <compilation debug="true" targetFramework="4.0">
  <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>
</compilation>

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>

<pages>
  <namespaces>
    <add namespace="System.Web.Helpers" />
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="System.Web.WebPages"/>
    <add namespace="ConsumerMVC3.App_Code"/>
  </namespaces>
  </pages>
</system.web>

<system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>
  <modules runAllManagedModulesForAllRequests="true"/>
  <security>
     <requestFiltering>
      <requestLimits maxAllowedContentLength="2147483648" />
    </requestFiltering>
  </security>
</system.webServer>

有人能给我一些建议吗?

谢谢, 科林

1 个答案:

答案 0 :(得分:0)

由于您没有节省太多,您是否考虑为视图创建ViewModel?它可以是模型的非常概括的版本,只是该特定视图所需的全部内容。它还会大大减少来回服务器的负载。

相关问题