Tag: global asax

ASP.NET MVC 4中未翻译自定义的错误消息

我想翻译validation消息“字段日期必须是日期”。 我已将以下键添加到Global.asax的Application_Start()中 ClientDataTypeModelValidatorProvider.ResourceClassKey = “ModelBinders”; DefaultModelBinder.ResourceClassKey = “ModelBinders”; 我在App_GlobalResources中创建了ModelBinders.resx,ModelBinders.nl.resx,ModelBinders.fr.resx。 我在.resx文件中添加了以下字符串资源(或翻译): Name Value ==== ===== FieldMustBeDate The field {0} must be a date. FieldMustBeNumeric The field {0} must be a number. PropertyValueInvalid The value ‘{0}’ is not valid for {1}. PropertyValueRequired A value is required. 当我提交日期字符串时,我将收到“FieldMustBeDate”的翻译。 当我提交无效日期(例如“01/01 / 201a”)时,我收到默认ModelBinders.resx中定义的“PropertyValueInvalid”的未翻译消息,而不是翻译…如何显示正确的翻译对于PropertyValueInvalid?

每个进程初始化System.Web.HttpApplication的次数

我有从我创建的自定义类扩展的global.asax ,名为MvcApplication ,它从System.Web.HttpApplication扩展而来。 在它的构造函数中,它按以下方式记录应用程序启动: protected MvcApplicationGeneral() { _log.Info(“logApplicationStartToTextFile”); } 当我查看日志文件时,这似乎被称为很多次,而不是每个应用程序启动一次。 我在Application_Start放置了另一个日志条目,似乎只调用了一次。 Global.asax类是按照请求实例化的,还是比每个应用程序只更新一次?

Global.asax – Application_Error – 如何获取页面数据?

我有这个代码: using System.Configuration; void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError().GetBaseException(); string ErrorMessage = ex.Message; string StackTrace = ex.StackTrace; string ExceptionType = ex.GetType().FullName; string UserId = Getloggedinuser(); string WebErrorSendEmail = ConfigurationManager.AppSettings[“WebErrorSendEmail”]; // save the exception in DB LogStuffInDbAndSendEmailFromDb(); } 这是(大部分)我的代码。 在一小部分情况下,我没有得到足够的信息。 我不知道exception起源于哪个页面。 如何获得与exception源自的页面相关的任何信息? 以下是最短消息的示例: Base-64 char数组的长度无效。 System.Web上的System.Web.UI.ObjectState.mat.UI.Object.UI上的System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)的System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)处的System.Convert.FromBase64String(String s)处的System.Convert.FromBase64String(String s) System.Web.UI.HiddenFieldPageStatePersister.Load()中的.UI.Util.DeserializeWithAssert(IStateFormatter formatter,String […]

分析器错误消息:无法加载类型’sometype’

我遇到一个错误,我现在暂时无法解决。 我想知道是否有人可以帮助确定此错误的原因? 我是asp / asax的新手。 经过一些研究,我认为我得到的错误是由于Web应用程序试图使用过时的代码。 我正在考虑使用Visual Studio和/或整个项目重建c#文件。 但是,我对C#和asp完全不熟悉,并且想知道如果这可以解决问题和/或是否有可能的替代解决方案可以给我一些建议。 错误信息 Parser Error Message: Could not load type ‘Inventory1.Global’. Source Error: 整个 Global.asax内容:

如何在生产中捕获HttpRequestValidationException

我有这段代码来处理我的global.asax.cs文件中的HttpRequestValidationException。 protected void Application_Error(object sender, EventArgs e) { var context = HttpContext.Current; var exception = context.Server.GetLastError(); if (exception is HttpRequestValidationException) { Response.Clear(); Response.StatusCode = 200; Response.Write(@”hello”); Response.End(); return; } } 如果我调试我的webapplication,它的工作完美。 但是当我把它放在我们的生产服务器上时,服务器会忽略它并生成“ 从客户端检测到一个有潜在危险的request.form值 ” – 错误页面。 我不知道到底发生了什么……如果有人知道问题是什么,或者我做错了什么……? 另外,我不想在web.config中将validaterequest设置为false。 服务器使用IIS7.5,我使用的是asp.net 3.5。 谢谢,布鲁诺