Tips for dotnet user-secrets

  • On the Windows platform, the secrets file are saved at /Users/yourusername/%APPDATA%/Microsoft/UserSecrets/{projectid}/secrets.json;
  • On Linux/Mac platform, the secrets file are saved at ~/.microsfot/usersecrets/{projectid}/secrets.json.

Believe it or not, .NET Core console application doesn't support user secrets in its default configuration. You can use dotnet command set or list your secrets, but actually, you cannot get its value through the IConfiguration object. What's a shame!

Finally, you may want to import secrets from one project to another project. I just wrote a small single-file script to save myself. Certainly, you can also use it if you like.

The tool has been published on Github, here it is.

SSH Config Tips: RemoteFoward and LocalForward

Suppose you have a local laptop without a public IP named A (192.168.1.7) and a remote server that has a public IP name named B (172.16.0.77) and another remote server C (172.16.0.78) which is in the same LAN with B. You can connect to B directly by ssh, and you cannot connect to C directly because C doesn't have an external IP address.

  1. You want to map port 5001 on A to the same port on B to make you local service temporarily public), you should add this line in laptop A's .ssh/config file:

     RemoteForward 5001 localhost:5001 #here localhost refers to A
    
  2. You want to map port 3306 on Host B (Remote machine) to the 3306 port on Host A (your laptop), you should add this line in laptop A's .ssh/config file:

     LocalForward 3306 localhost:3306  # here localhost refers to B
    
  3. You want to map port 22 on machine C to the 8045 port on A, add this line:

     LocalFoward 8045 172.16.0.78:22
    

Finally, the following code shows the final configuration in your ~/.ssh/config file

            Host B
		HostName b.somedomain.com
		Port 22
		RemoteForward 5001 localhost:5001
		LocalForward 3306 localhost:3306
		LocalForward 8045 172.16.0.78:22

Thus, after you get connected with Host B through this config file,

  • You can tell your friends or colleague to visit your local website by visiting http://b.somedomain.com:5001.
  • You can get connected to Host C directly by running ssh -p 8045 username@localhost command.
  • You can also directly visit the locally deployed MySQL service on Host B by connecting your local laptop's 3306 port.

Methods for receiving JSON data in an Asp.NET core Controller

  1. [HttpPost] 
    public  IActionResult Fill([FromBody] dynamic data)
    {
         string amount = data.amount.GetString();
    }
    
  2.  [HttpPost] 
     public  IActionResult Fill()
     {
          string dataStr = new StreamReader(Request.Body, Encoding.UTF8).ReadToEnd();
          var data = JObject.Parse(dataStr);
          string amount = data.value.amount;
     }
    
  3. [HttpPost] 
    public  IActionResult Fill([FromBody] YourType data)
    {
        string amount = data.amount;
    }
    

First post

I just finished the installation for the Chryp lite blog system. I met a small issue related to its compatibility with MySQL version 8 but I managed to resolve it. Happy!

The issue is that "groups" word has become a reserved keyword in MySQL 8.x, and unfortunately, there's a table in this blog system named "groups" too. I first tried to use "``" to encapsulate the table name and I failed quickly because there are too many places using the table name.

Fortunately, the install program supports me to add a table prefix for all tables. So it was resolved by simply adding a table prefix!

Happy!