【问题标题】:@using(Html.BeginForm()) returning Format exception mvc4@using(Html.BeginForm()) 返回格式异常 mvc4
【发布时间】:2013-04-12 22:46:45
【问题描述】:

我有一个 MVC4 Web 应用程序在我的开发机器上运行,没有任何问题,但是一旦我将它部署到主机服务器,我就会在 @using(Html.BeginForm()) 上抛出以下异常。

字符串未被识别为有效的布尔值。 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。 异常详细信息:System.FormatException:字符串未被识别为有效的布尔值。 源错误: 第 4 行: 第 5 行: 第 6 行:@using(Html.BeginForm(new { returnurl = ViewBag.Returnurl })) 第 7 行:{ 第 8 行:@Html.AntiForgeryToken() 源文件:e:\Sites\familybook\Views\Login\Login.cshtml 行:6 堆栈跟踪: [FormatException:字符串未被识别为有效的布尔值。] System.Boolean.Parse(字符串值)+12636900 System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +12819466 System.Web.Mvc.ViewContext.ScopeGet(IDictionary`2 scope, String name, TValue defaultValue) +89 System.Web.Mvc.ScopeCache..ctor(IDictionary`2 范围) +48 System.Web.Mvc.ScopeCache.Get(IDictionary`2 范围,HttpContextBase httpContext) +282 System.Web.Mvc.ViewContext.GetClientValidationEnabled(IDictionary`2 范围,HttpContextBase httpContext)+9 System.Web.Mvc.Html.FormExtensions.FormHelper(HtmlHelper htmlHelper, String formAction, FormMethod 方法, IDictionary`2 htmlAttributes) +162 System.Web.Mvc.Html.FormExtensions.BeginForm(HtmlHelper htmlHelper,对象 routeValues)+192 ASP._Page_Views_Login_Login_cshtml.Execute() 在 e:\Sites\familybook\Views\Login\Login.cshtml:6 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125 System.Web.WebPages.StartPage.ExecutePageHierarchy() +143 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +181 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext 上下文)+380 System.Web.Mvc.c__DisplayClass1a.b__17() +33 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter 过滤器,ResultExecutingContext preContext,Func`1 延续)+613 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 过滤器, ActionResult actionResult) +263 System.Web.Mvc.Async.c__DisplayClass25.b__22(IAsyncResult asyncResult) +230 System.Web.Mvc.c__DisplayClass1d.b__18(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.c__DisplayClass4.b__3(IAsyncResult ar) +20 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53 System.Web.Mvc.Async.c__DisplayClass4.b__3(IAsyncResult ar) +20 System.Web.Mvc.c__DisplayClass8.b__3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.c__DisplayClass4.b__3(IAsyncResult ar) +20 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375 版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.272

主机服务器是 Windows server 2008 R2 64 位,安装了 IIS 7.5 和最新的操作系统更新和 .NET 4 框架。

有趣的是,当我在使用 Windows 更新更新服务器之前,我在部署之前没有收到此错误。我注意到的另一件事是,如果我将发布类型设置为调试应用程序没有任何问题,而发布发布类型则没有。

我也尝试部署到我的开发机器上的本地文件夹,然后将内容复制到主机服务器,但得到了相同的最终结果。

编辑:

 @model FamilyBook.Models.Account.LoginUserModel

@Scripts.Render("~/bundles/jqueryval")

<section>
    @using(Html.BeginForm(new { returnurl = ViewBag.Returnurl }))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)

        <fieldset>
            <legend>Login with local account</legend>

            <div class="editor-label">
                @Html.LabelFor(model => model.Username)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Username)
                @Html.ValidationMessageFor(model => model.Username)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.Password)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(model => model.Password)
                @Html.ValidationMessageFor(model => model.Password)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.RememberMe)
            </div>
            <div class="editor-field">
                @Html.CheckBoxFor(model => model.RememberMe)
            </div>

            <p>
                <input type="submit" value="Login" />
            </p>

        </fieldset>
    }
</section>

【问题讨论】:

  • 试图删除所有cookie并再次测试,您也可以发布您的视图代码吗?
  • 请贴出您的观点代码
  • @Jorge 尝试从不同机器上的主机服务器访问该网站,结果相同。

标签: asp.net-mvc-4 web-config iis-7.5


【解决方案1】:

问题的根本原因是,当对自定义键的 appSettings 执行 web.conf 转换时,它们用第一个自定义键的相同值覆盖了所有其他键。所以对 -> 做一个简单的改变就解决了这个问题。 这可以在堆栈跟踪中看到,当调用 MVC System.Web.Mvc.ViewContext.GetClientValidationEnabled 中的此函数以检查 clientSideValidation 是否启用时,应用程序崩溃。更多信息可以在这个线程中找到http://forums.asp.net/t/1924833.aspx/1?Format+exception+on+Html+BeginForm+String+was+not+recognized+as+a+valid+boolean

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多