In classic .NET Framework applications, we have used System.Net.NetworkInformation.Ping class to Ping a host address. This API is not included by default in .NET Core, even in version 2.0. Here is how to do it in a .NET Core way. First, we need to reference a package System.Net.Ping Install-Package System.Net.Ping This will give us the same API set as .NET Framework. Then, in your .NET Core code, …
There's official update for NLog targeting ASP.NET Core 2.x, for the latest methods please refer to https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-2 Recently I am porting a classic ASP.NET MVC 5 project to .NET Core 2.0, in order to run it on Linux. One of the parts that has differences between .NET Fx and .NET Core is logging. I choose NLog as my logging providor, let's …
In classic ASP.NET we used to get client IP Address by Request.UserHostAddress. But this does not apply to ASP.NET Core 2.0. We need a different way to retrieve HTTP Request information.
1. Define a variable in your MVC controller
private IHttpContextAccessor _accessor;
2. DI into the controller's constructor
public SomeController(IHttpContextAccessor accessor)
{
_accessor = accessor; …
The InkCanvas in UWP only got pens by default, it can not perform Undo or Redo. To implement this, we will need to code for ourselves. Official document covered Undo functionalilty, but not redo. Today, I have successfully done it, and I'd like to share with you. First, you need to add two custom buttons on the InkToolbar for Undo / Redo 1. Undo the Ink We need a few APIs. To …
Today, I was rewriting an old ASP.NET MVC5 Demo project to ASP.NET Core, and found that the way we used to read Web.config by ConfigurationManager.AppSettings[] is no longer working. .NET Core has many new ways to achieve this. I picked one that suitable for my project. Here is how I do it. The Classic ASP.NET Code web.config Controller private static CloudBlobContainer GetBlobContainer() …
If you are using Website on Microsoft Azure (Currently renamed to Web Apps), you will find the .woff web font is not working in IE, it returns 404. Based on my experience, this is because IIS is not configured to use the correct MimeType. However, we can not operate the IIS on Azure, there's no RDP into an Azure Web Apps backend machine. How can we do that? In fact, after IIS7, the MineType is …
ASP.NET MVC里面我们要自定义ActionFilter的时候会发现有4个方法可以override:OnActionExecuting,OnActionExecuted,OnResultExecuting,OnResultExecuted。他们分别在什么时候执行一直是困扰人类的一个问题。我代表人类做了一个简单的实验: 首先自定义一个ActionFilter,每个方法执行的时候都在VS的OUTPUT窗口输出信息: public class TestActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { Debug.WriteLine("OnActionExecuting"); …