Asp.net mvc 4 @使用(Html.BeginForm())返回格式异常mvc4

Asp.net mvc 4 @使用(Html.BeginForm())返回格式异常mvc4,asp.net-mvc-4,web-config,iis-7.5,Asp.net Mvc 4,Web Config,Iis 7.5,我有一个MVC4 web应用程序在我的开发机器上运行,没有任何问题,但是一旦我将它部署到主机服务器上,我就会在@上使用(Html.BeginForm())引发以下异常 字符串未被识别为有效的布尔值。 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源。 异常详细信息:System.FormatException:字符串未被识别为有效的布尔值。 源错误: 第4行: 第5行: 第6行:@using(Html.BeginForm(new{retu

我有一个MVC4 web应用程序在我的开发机器上运行,没有任何问题,但是一旦我将它部署到主机服务器上,我就会在
@上使用(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 堆栈跟踪: [格式异常:字符串未被识别为有效的布尔值。] System.Boolean.Parse(字符串值)+12636900 System.Convert.ChangeType(对象值、类型转换类型、IFormatProvider提供程序)+12819466 System.Web.Mvc.ViewContext.ScopeGet(IDictionary`2作用域,字符串名称,TValue defaultValue)+89 System.Web.Mvc.ScopeCache..ctor(IDictionary`2 scope)+48 System.Web.Mvc.ScopeCache.Get(IDictionary`2 scope,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,对象路由值)+192 ASP.\u Page\u Views\u Login\u Login\u 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__显示Class1A.b_17()+33 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter筛选器,ResultExecutingContext预文本,Func`1 continuation)+613 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext ControllerContext,IList`1过滤器,ActionResult ActionResult)+263 System.Web.Mvc.Async.c__显示类25.b__22(IAsyncResult asyncResult)+230 System.Web.Mvc.c_uuudisplayClassId.b_uuu18(IAsyncResult asyncResult)+28 System.Web.Mvc.Async.c_uuuudisplayClass4.b_uuuu3(IAsyncResult ar)+20 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+53 System.Web.Mvc.Async.c_uuuudisplayClass4.b_uuuu3(IAsyncResult ar)+20 System.Web.Mvc.c_uuudisplayClass8.b_uuu3(IAsyncResult asyncResult)+42 System.Web.Mvc.Async.c_uuuudisplayClass4.b_uuuu3(IAsyncResult ar)+20 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+469 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+375 版本信息:Microsoft.NET Framework版本:4.0.30319;ASP.NET版本:4.0.30319.272 主机服务器是Windows server 2008 R2 64位,其中安装了IIS 7.5以及操作系统和.NET 4 framework的最新更新

有趣的是,在我之前部署时,直到我使用windows Update更新服务器后才出现此错误。我注意到的另一件事是,如果我将发布类型设置为调试应用程序,则应用程序可以正常工作,而发布类型则不能正常工作

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

编辑:

@model FamilyBook.Models.Account.LoginUserModel
@Scripts.Render(“~/bundles/jqueryval”)
@使用(Html.BeginForm(new{returnurl=ViewBag.returnurl}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
使用本地帐户登录
@LabelFor(model=>model.Username)
@EditorFor(model=>model.Username)
@Html.ValidationMessageFor(model=>model.Username)
@LabelFor(model=>model.Password)
@Html.PasswordFor(model=>model.Password)
@Html.ValidationMessageFor(model=>model.Password)
@LabelFor(model=>model.RememberMe)
@CheckBoxFor(model=>model.RememberMe)

}
问题的根本原因是,当对自定义密钥的appSettings执行web.conf转换时,它们用与第一个自定义密钥相同的值重写了所有其他密钥。因此,对->进行简单更改就解决了问题。
这可以在堆栈跟踪中看到,当调用MVC System.Web.MVC.ViewContext.GetClientValidationEnabled中的此函数以检查是否启用了clientSideValidation时,应用程序会在堆栈跟踪中崩溃。在该线程中可以找到更多信息

尝试删除所有cookie并再次测试,您是否可以发布视图的代码?Pl请轻松发布您的密码view@Jorge尝试从不同计算机上的主机服务器访问网站,结果相同。 String was not recognized as a valid Boolean. 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.FormatException: String was not recognized as a valid Boolean. Source Error: Line 4: Line 5: Line 6: @using(Html.BeginForm(new { returnurl = ViewBag.Returnurl })) Line 7: { Line 8: @Html.AntiForgeryToken() Source File: e:\Sites\familybook\Views\Login\Login.cshtml Line: 6 Stack Trace: [FormatException: String was not recognized as a valid Boolean.] System.Boolean.Parse(String value) +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 scope) +48 System.Web.Mvc.ScopeCache.Get(IDictionary`2 scope, HttpContextBase httpContext) +282 System.Web.Mvc.ViewContext.GetClientValidationEnabled(IDictionary`2 scope, HttpContextBase httpContext) +9 System.Web.Mvc.Html.FormExtensions.FormHelper(HtmlHelper htmlHelper, String formAction, FormMethod method, IDictionary`2 htmlAttributes) +162 System.Web.Mvc.Html.FormExtensions.BeginForm(HtmlHelper htmlHelper, Object routeValues) +192 ASP._Page_Views_Login_Login_cshtml.Execute() in 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 context) +380 System.Web.Mvc.c__DisplayClass1a.b__17() +33 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, 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 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
 @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>