Tag: asp.net

如何强制jqGrid 4.10.1-pre编码’字符总是

免费jqgrid使用设置 autoencode: true 网格定义包含: $grid.jqGrid({ url: ‘/admin/API/Entity’, datatype: “json”, editurl:’/admin/Detail/Edit’ 在内联编辑中<a字符输入Nimetus列,数据以url编码格式发布到服务器。 Request URL:http://localhost:52216/admin/Detail/Edit?_entity=DokG&_dokumnr=135322&_vmnr=0 Request Method:POST Status Code:490 OK Response Headers view source Cache-Control:private, s-maxage=0 Content-Length:122 Content-Type:application/json; charset=utf-8 Date:Mon, 23 Nov 2015 15:31:54 GMT Server:Microsoft-IIS/10.0 X-AspNet-Version:4.0.30319 X-SourceFiles:=?UTF-8?B?STpccmFhbWF0XEVldmFXZWJcRWV2YS5FcnBcRGV0YWlsXEVkaXQ=?= Request Headers POST /admin/Detail/Edit?_entity=DokG&_dokumnr=135322&_vmnr=0 HTTP/1.1 Host: localhost:52216 Connection: keep-alive Content-Length: 1724 Accept: */* Origin: http://localhost:52216 X-Requested-With: XMLHttpRequest Query String […]

如何在调用JSON Web服务时获取exception信息

在.NET 3.5中,我有以下代码: [WebService(Namespace = “http://kitchenpc.com/schemas/”)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService] public class KitchenPC : System.Web.Services.WebService { [WebMethod] public LogonResult Logon(string username, string password) { //If username and password are not valid… throw new InvalidUsernameOrPasswordException(); } } 当我调用它时,如果我传入了无效的用户名和密码,则会抛出InvalidUsernameOrPasswordException ,我可以通过查看error.get_exceptionType()来捕获Javascript中的exception。 这是因为Web服务将在JSON中序列化exception信息。 但是,一旦我升级到.NET 4.5,这就破了。 现在,当我传入无效的用户名和密码时,我收到HTTP响应: HTTP/1.1 500 Internal Server Error Cache-Control: private Content-Type: application/json; charset=utf-8 Server: Microsoft-IIS/7.5 jsonerror: true […]

无法在C#中解析Oracle时间戳

我有Oracle的时间戳: string timestamp = “23-JUN-14 09.39.04.000000000 AM”; 我无法将其解析为系统日期时间对象。 我用了: CultureInfo provider = CultureInfo.InvariantCulture; String format = “yy-MMM-dd hh:mm:ss:fffffff”; string timestamp = “10-DEC-07 10.32.47.797201123 AM”; { var date = DateTime.ParseExact(timestamp, format, provider); DateTime dateTime = DateTime.ParseExact(timestamp.ToString(), “dd-MMM-y HH:mm:ss”, CultureInfo.InvariantCulture); } 它仍然传递错误。 它在m后工作7 f但不超过。 我用过Parse尝试ParseExact – 有什么办法吗?

通用存储库,CreateObjectSet ()方法

我试图实现一个通用的存储库,我现在就有这个: using System; using System.Collections.Generic; using System.Linq; using System.Data; using System.Data.Entity.Core.Objects; using Web_API.Models; namespace Web_API.DAL { class GenericRepository : IRepository where T : class { private ApplicationDbContext entities = null; IObjectSet _objectSet; public GenericRepository(ApplicationDbContext _entities) { entities = _entities; _objectSet = entities.CreateObjectSet(); } … 我在使用此方法调用时遇到问题: entities.CreateObjectSet(); 它应该没问题,但我得到这个错误: 我已经将System.Data.Entity添加到我的项目中,此时我不知道还能做什么。 我正在关注本教程http://www.codeproject.com/Articles/770156/Understanding-Repository-and-Unit-of-Work-Pattern 。 有谁知道如何解决这个问题?

EditorFor Inheritance Model MVC

我的post调用没有返回正确的模型类型。 它始终使用baseObject而不是我从Get传入的正确派生对象 RestaurantViewModel.cs public class RestaurantViewModel{ public Food BaseFoodObject{get;set;} } Food.cs public class Food{ public string Price{get;set;) } Bread.cs – 从食物inheritance public class Bread:Food{ public int Unit{get;set;} } Milk.cs – 从食物中inheritance public class Milk:Food{ public string Brand{get;set} } 面包模板的编辑。 显示单位并允许用户编辑 的index.html @Model RestaurantViewModel @using(Html.BeginForm(“SaveFood”, “Food”)) { @Html.EditorFor(m=>m.BaseFoodObject) } Bread.cshtml @Model Bread @Html.TextboxFor(bread=>bread.Unit) FoodController.cs public ActionResult […]

如何避免加载不合规的程序集

ASP.NET .NET 4.6 MVC4应用程序加载了unnessecary assemblie,eq。 System.Data.OracleClient。 没有使用Oracle。 使用控制器中的代码创建程序集依赖项 var sb = new StringBuilder(); foreach (Assembly b in AppDomain.CurrentDomain.GetAssemblies()) { sb.AppendLine(b.FullName); foreach (AssemblyName an in b.GetReferencedAssemblies()) sb.AppendLine(” ” + an.Name); } 输出低于。 根据此System.Web引用System.Design和System.Design对System.Data.OracleClient的引用 MVC应用程序在内存有限的VPS服务器中运行。 如何解决这个问题,以便不加载unnessecary程序集? 这有望在VPS服务器中释放一些内存。 mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a mscorlib System.Drawing System System.Configuration System.Core System.Data System.Xml System.DirectoryServices System.EnterpriseServices System.Web.RegularExpressions System.Design System.Web.ApplicationServices […]

如何在ASP.NET 5 MVC中没有模型的情况下从查询中访问数据

我试图使用EF7在控制器内执行查询并在表中显示数据。 这是我的模特: public class Resources { public int id { get; set; } public string name { get; set; } public string descr { get; set; } public string resourcePath { get; set; } public string method { get; set; } public string format { get; set; } public virtual ICollection Tags { get; set; […]

什么是处理exception以及如何在asp.net中处理它们的最佳方法

首先,我已经熟悉了简单的exception处理语法,但我要问的是最佳位置,最佳时间以及处理它们的最佳方法。 我正在构建一个N层应用程序。 所以我认为DAL有时会产生一些错误来处理..而我刚刚了解了SqlException类,该类的处理是什么? 我曾经看过一个处理SqlException的代码,然后它处理Exception! 在了解了实践以及我将要处理它们之后,我计划创建一个连接数据库并在数据库中记录错误的方法,以便我可以解决它,但我仍然不知道应该提供哪些信息收集让我识别整个情况! 我认为exception处理并不是什么大问题。 但我时不时地读到一些奇怪的建议 – 我从来没有理解过 – 在问题评论中却没有人能回答我,因为这是一些非常古老的问题! “不要只是明确地捕捉exception” “应用程序中更高层使用的代码必须始终只抛出exception,而不必担心如何处理它们。” 编辑 那么Page_Error事件和Application_Error ..我看到它们是处理错误的好习惯

如何使用C#在Webforms中获取文本框的GotFocus,LostFocus事件

在创建网站时,我无法获得文本框的GotFocus,LostFocus事件。 我只是想。 正如我之前在我的问题中提到的,当焦点是winforms中另一个文本框的文本时,如何将一个文本框的值放到另一个文本框中。 我能够以windowsforms完成它。 但是,当我在网站上尝试相同的时候,我无法将这些事件发送给他们…..应该使用Java脚本来获取这些事件吗? Pelase有帮助

如何在asp.net web应用程序中调用javascript方法

我想在ac#函数中使用javascript函数 protected void button1_Click(object sender,EventArgs e){ //javascript function call ex. /* boolean b=the return of: function update() { var result = confirm(“Do you want to delimit the record?”) if (result) {return true;} else { return false; } } */ } 我怎么能做这样的事情? 我想当用户按下是,返回true,我知道他按了是…我可以这样做吗?