【知识笔记】Debugging 关于web.config中<customErrors>节点说明 【.NET】AutoMapper学习记录

一、启动调试出现 无法启动程序 当前状态中是非法

VS工具--选项--调试--常规--启用asp.net的JavaScript调试(chrome和ie)去掉勾选

二、web.config中<customErrors>报错

<customErrors>节点用于定义一些自定义错误信息的信息。

此节点有Mode和defaultRedirect两个属性,其中

defaultRedirect属性是一个可选属性,表示应用程序发生错误时重定向到的默认URL,如果没有指定该属性则显示一般性错误;

Mode属性是一个必选属性,它有三个可能值,它们所代表的意义分别如下:
Mode 说明
On 表示在本地和远程用户都会看到自定义错误信息。
Off 禁用自定义错误信息,本地和远程用户都会看到详细的错误信息
RemoteOnly 表示本地用户将看到详细错误信息,而远程用户将会看到自定义错误信息。
这里有必要说明一下本地用户和远程用户的概念。当我们访问asp.net应用程时所使用的机器和发布asp.net应用程序所使用的机器为同一台机器时成为本地用户,反之则称之为远程用户。

开发调试阶段为了便于查找错误Mode属性建议设置为Off,而在部署阶段应将Mode属性设置为On或者RemoteOnly,以避免这些详细的错误信息暴露了程序代码细节从而引来黑客的入侵。

所以想看具体的错误,有两种方式:将mode设置为Off,或者直接在服务器上复现刚才发生错误的操作,看详细的错误信息。

参考:关于web.config中<customErrors>节点说明

三、WCF报错

1、WCF运行不起来

System.ServiceModel.EndpointNotFoundException:“没有终结点在侦听可以接受消息的

 "ExceptionMessage": "没有终结点在侦听可以接受消息的 http://localhost.dev.xxx.com/Services/yyyService.svc。这通常是由于不正确的地址或者 SOAP 操作导致的。如果存在此情况,请参见 InnerException 以了解详细信息。","ExceptionType": "System.ServiceModel.EndpointNotFoundException",

可能是 wcf服务没启动?

从IIS_Express中打开wcf站点,看是否有报错,

可能错误:未能加载配置文件;web.Config中wcf路径配置有误

路径错误,看是否需要修改.vs\config\applicationhost.config 中的虚拟路径  <virtualDirectory path="/Service" physicalPath="D:\sources.git\xxx\yyy" />

配置文件拷贝后,WCF运行起来。

2、调试不进断点

 调试选项里面的 “仅我的代码”,取消选中

3、无法自动进入并单步执行服务器。调试器未能在服务器进程中停止

以上设置都配置好后,清理解决方案,重新生成。

 4、域名绑定问题

可以看到,restapi请求WCF时 没有成功。

在本地看到wcf是ok的。但是在restapi所在的服务器上请求wcf是不行的。于是看服务器上的host,发现没有绑定 wcf域名对应的ip。

四、DBContext报类型初始值设定项引发异常

查看配置文件,configSource节点

<appSettings configSource="VConfigs\Dev\appSettings.config">

    <add key="ClientSettingsProvider.ServiceUri" value=""/>

  </appSettings>

手动改为

<appSettings configSource="VConfigs\Dev\appSettings.config"/>

参考:http://www.it1352.com/21840.html

五、  Missing type map configuration or unsupported mapping

Missing type map configuration or unsupported mapping. Mapping types: Discount -> DiscountEntity Ferry.Data.Models.Discount ->Entity.DiscountEntity Destination path: List`1[0] Source value: Data.Models.Discount,錯誤源:

参考:http://www.cnblogs.com/dudu/p/5875579.html

从 GitHub 上签出 AutoMapper 的源代码一看 Mapper.Initialize() 的实现,恍然大悟。

public static void Initialize(Action<IMapperConfigurationExpression> config)

{

    Configuration = new MapperConfiguration(config);

    Instance = new Mapper(Configuration);

}

原来每次调用 Mapper.Initialize() 都会创建新的 Mapper 实例,也就是多次调用 Mapper.Initialize() 只有最后一次生效。

更多参考:【.NET】AutoMapper学习记录

六、the current .NET SDK does not support targeting .NET Standard 2.0. Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0

通过这句英文一直以为是 .net framework 2.0未安装。

安装以后引用不报错(没有黄色感叹号),编译的时候却还是报错。

 找到原因,原文地址

https://stackoverflow.com/questions/45732236/the-current-net-sdk-does-not-support-targeting-net-standard-2-0-error-in-visua

 安装 .net core 2.0可以解决。

vs重启后,出错的项目 属性。重新选择目标平台。

七、未能找到文件

“D:\sources.git\wingontravel_SZ\Ferry\DEV\Ferry\Ferry.Offline\App_Data\XmlDocument.xml”

重新编译offline项目,并且index.html为启动页面。。

让D:\sources.git\wingontravel_SZ\Ferry\DEV\Ferry\Ferry.Offline\App_Data 目录下生成这个xml文件,或者拷贝过来。

八、初始化异常或内存不足

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

日志记录的详细信息:

System.TypeInitializationException: The type initializer for 'Ferry.Data.Models.FerryDBContext' threw an exception.

---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.Utilities.TypeExtensions' threw an exception.

---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.Core.Metadata.Edm.MetadataItem' threw an exception.

---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

咋一看是数据库(或者EF连接)初始化的问题。

若期间没有动过服务器或者DB,,则大致可以认为是服务器问题,可以重启服务,只重启出问题的应用程序池

九、https网站中样式资源没起作用

F12 看到js报错:Mixed Content: The page at 'https://xxx.com//app/#booking/search'

was loaded over HTTPS, but requested an insecure stylesheet 'http://xxx.com/Site/Styles/offline/main.css'.

This request has been blocked; the content must be served over HTTPS.

 

http://xxx.com/Site/Styles/offline/main.css这个资源(位于index.html中的<head>标签中)被阻塞了,

原因:在https网站中,载入http网站的资源(网页、图片等),会被浏览器阻拦。HTTPS 是 HTTP over Secure Socket Layer,以安全为目标的 HTTP 通道,在 HTTPS 承载的页面上不允许出现 http 请求

正确应该是https://xxxx.com/Site/Styles/offline/main.css

十、未能加载文件或程序集

打开WCF时:未能加载文件或程序集“MongoDB.Bson, Version=2.2.3.3, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。系统找不到指定的文件。

找到相应的目录:D:\sources.git\xxx\DEV\yyy.Offline.Service.Site\bin

看它里面是否有MongoDB.Bson程序集,没有的话copy一份进去。

十一、分析器错误信息: 未能加载类型“xxxx.Global”

解决方法: 删除此项目下bin里面的所有dll,清理 重新生成。

十二、VS中修改代码,再断点调试,发现命中的还是修改前的代码

解决方法: 清理解决方案,再重新生成。

十三、LINQ to Entities 不识别方法“System.DateTime ToDateTime(System.String)”,因此该方法无法转换为存储表达式

 

因为EF不支持复杂类型(如实体)的直接检索,只能用简单类型(string、int、guid等)

 

 

 

 

猜你喜欢

转载自www.cnblogs.com/peterYong/p/10647999.html
今日推荐