2019年5月19日 星期日

使用 Elmah 來記錄 ASP.NET 網站的錯誤

https://www.huanlintalk.com/2013/02/something-about-elmah-error-logging.html

https://blog.miniasp.com/post/2013/03/12/ASPNET-MVC-4-and-ELMAH-Integration


    <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
      <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
    </sectionGroup>

上面區塊宣告的要加入Web.config否則解析xml會認不得<elmah>
錯誤碼   0x80070032
設定錯誤   無法讀取設定區段 'elmah',因為它缺少區段宣告

設定來源:

  125:   </system.data>
  126:   <elmah>
  127:     <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/Elmah.Errors" />


ASP.NET Core 的檔案上傳

net core 2.2

https://docs.microsoft.com/zh-tw/aspnet/core/mvc/models/file-uploads?view=aspnetcore-2.2

https://github.com/aspnet/AspNetCore.Docs/tree/master/aspnetcore/mvc/models/file-uploads/sample/FileUploadSample


2019年5月18日 星期六

ASP.NET移轉到ASP.NET Core-取得 Request URL 的各個部分

https://sites.google.com/site/netcorenote/asp-net-core/get-scheme-url-host

asp.net原本用Request.Url 在Core大部分需要改使用Context.Request
Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(Request) => http://localhost:60467/Home/About 
【Request.Url.Scheme】Context.Request.Scheme => http 
【Request.Url.Host】Context.Request.Host.Host => localhost 

【Request.Url.Authority】Context.Request.Host.Value => localhost:60467 
【Request.Url.LocalPath】Context.Request.Path => /Home/About 
【Request.Url.Port】Context.Request.Host.Port => 60467



ASP.NET 如何取得 Request URL 的各個部分
https://blog.miniasp.com/post/2008/02/10/How-Do-I-Get-Paths-and-URL-fragments-from-the-HttpRequest-object

ASP.NET內抓取網址的方式一覽表(Request)
https://demo.tc/Post/230

.NET Core迁移续集Win下莫名其妙的超时

https://mp.weixin.qq.com/s/23dFe5Kbe3ES8X1jH80B4w

无论你是new一个静态HttpClient还是通过HttpClientFactory去创建HttpClient,记得要将UseProxy=false

2019年4月20日 星期六

取得 Entity Framework 存取 DB 時的實際 SQL Script

https://blog.yowko.com/entityframework-log-sql/

LocalDbConnectionFactory和SqlconnectionFactory


System.Data.Entity.Infrastructure Namespace
https://docs.microsoft.com/en-us/dotnet/api/system.data.entity.infrastructure?view=entity-framework-6.2.0


SqlConnectionFactory Class
https://docs.microsoft.com/en-us/dotnet/api/system.data.entity.infrastructure.sqlconnectionfactory?view=entity-framework-6.2.0
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlconnectionFactory, EntityFramework">


LocalDbConnectionFactory Class
https://docs.microsoft.com/en-us/dotnet/api/system.data.entity.infrastructure.localdbconnectionfactory?view=entity-framework-6.2.0
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">


[ASP.NET MVC] DB Connection 從LocalDb Connection變更為 SQL Server Connection
https://jeterh.blogspot.com/2015/08/aspnet-mvc-db-connection-localdb.html


ORACLE資料庫
<entityFramework>
  <defaultConnectionFactory type="Oracle.ManagedDataAccess.EntityFramework.OracleConnectionFactory, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
  <providers>


MYSQL資料庫
https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html
<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
    <providers>
        <provider invariantName="MySql.Data.MySqlClient"
            type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
        <provider invariantName="System.Data.SqlClient"
            type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
</entityFramework>


DB2資料庫
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="IBM.Data.DB2" type="IBM.Data.DB2.EntityFramework.DB2ProviderServices, IBM.Data.DB2.EntityFramework, Version=10.5.5.6, Culture=neutral, PublicKeyToken=7c307b91aa13d208" />
</providers>
</entityFramework>