1.C# 中的虚方法 和 C++中的做用一致,能让指向子类的父类指针优先到子类中寻找方法,而不是直接调用父类中的方法。html
看一段例子回忆下:web
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Person student = new Student(); student.speak(); student.sing(); } } class Person { public virtual void speak() { Console.WriteLine("person speak"); } public void sing() { Console.WriteLine("person sing"); } } class Student:Person { override public void speak() { Console.WriteLine("student speak"); } new public void sing() { Console.WriteLine("student sing"); } } }
输出以下:sql
2. 在程序中使用 HttpContext.Current.Session["CurrentAdmin"] = objAdmin; 这类的与session相关的函数后,asp.net 框架会默认添加一个名为 ASP.NET_SessionId 的cookie,这个cookie有24个字符,用来让系统区分请求所对应的session。若是确实不但愿这个字段出如今cookie里,能够经过调用 Response.Cookies["ASP.NET_SessionId"].Expires = DateTime.Now.AddYears(-1); 让这个cookie过时,游览器就会自动删除这个cookie。另外这个cookie是保存在内存中的,并不会在磁盘上,因此关了游览器,cookie也就没了。数据库
3. 今天开发遇到一个bug,说的是关于assembly未正确配置,其实这个assembly在.NET中就是对应的dll文件,若是出错,就须要看看是否是在bin文件夹中缺失了某个dll。express
4.今天作一个上传功能,在服务器端用的是Server.MapPath 这个方法得到路径,具体的路径是/Upload ,在默认iis express 运行环境下,没有问题,后来为了调试,把程序放到了本机的IIS上,结果上传没有错误,却取不到数据了。后来发现,这个网站被当作了子站发布在了IIS的默认网站下,那么Server.MapPath 其实返回的是http://localhost/Upload ,也就是在主站点下的upload文件夹,而不是 子站的http://localhost/webapplication/Upload. 因此上传虽然成功了,可是上传的位置错了!要解决问题,把网站做为单独主站点就能够了。服务器
个人错误配置以下:cookie
这种在主机端口号后,还有一个路径的写法,系统就会为咱们建立子文件夹存放数据,可是运行时取到的server的path信息,会是主站点的虚拟路径。session
正确的作法是,先在IIS中建立一个站点,配置好信息,以后在vs中进行配置,修改后的截图以下:app
5. 今天在写Entity Framework相关代码时,没有把实体中的关联属性声明为Virtual,结果发现,没法从数据库读取关联属性了,结果所有是null,后来查看了如下文章:框架
这里面说到了,若是不使用virtual对 navigation 属性声明,取出的对象就不会包含navigation属性的相关内容,其实就是不会对navigation属性进行sql检索操做。但即便不声明,也能够经过其余方法读取内容。好比如下代码:
context.Votes.Include(v => v.ToUser).ToListAsync();
这样检索的话,即便 vote 的 toUser 属性没有声明为virtual,也能够被sql一次性读取出来。另外,目前.Net Core 中的 EntityFramework core 默认不支持virtual这种懒加载。
再看看stackoverflow上关于ef中的virtual的说明:
If you opt to never use the lazy loading or change tracking features of the Entity Framework (which is not the default) then you needn't declare any of your navigation properties as virtual. You are then responsible for loading those navigation properties yourself, either using what the Entity Framework refers to as "eager loading", or manually retrieving related types across multiple database queries.
6.关于IIS 中的 module 和 handler。 在web.config里,常常能够看到对module 和 handler的配置section。这里的module和handler既能够是本身写的,也能够是系统提供的。我对module的理解就是,它处理通用的逻辑,好比,身份验证,一个请求能够通过任意多个module的处理。handler针对的是某一类资源的,好比aspx,是真正的处理请求,返回数据的结构,一个请求,只能通过一个handler的处理。推荐一个文章 https://www.cnblogs.com/fengzheng/p/3666774.html。