Skip to content

Instantly share code, notes, and snippets.

@huanlin
huanlin / ASP.NET URL and Path.txt
Last active February 18, 2019 02:22
ASP.NET URL and Path related methods.
Related Properties
- HttpRuntime.AppDomainAppVirtualPath
- Request.ApplicationPath
Methods for getting physical file path:
- System.Web.HttpContext.Current.Server.MapPath()
Methods for generating content URL:
@huanlin
huanlin / MD5Hash.cs
Created September 12, 2013 15:46
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile() is obsoleted, use MD5 class instead.
string MD5Hash(string str)
{
// return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd);
var md5 = MD5.Create();
var hashedBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
var hashedStr = String.Join("", hashedBytes.Select(x => x.ToString("x2")));
return hashedStr;
}
<unity>
<namespace name="Service.Class" />
<assembly name="Service" />
<container>
<register type="IOwnExpenseDService" mapTo="OwnExpenseDService" />
<register type="Model.Dal.IOwnExpenseDDal, Model" mapTo="Model.Dal.OwnExpenseDDal, Model" />
</container>
</unity>
@huanlin
huanlin / di-ex01-1.cs
Created August 13, 2014 01:09
Example code of DI book
interface IMessageService
{
void Send(User user, string msg);
}
class EmailService : IMessageService
{
public void Send(User user, string msg)
{
// 寄送電子郵件給指定的 user (略)
@huanlin
huanlin / NotificationManager
Last active August 29, 2015 14:10
Unity Example 6-1
public interface INotificationManager
{
void Notify(string to, string msg);
}
public class NotificationManager : INotificationManager
{
private readonly IMessageService _msgService = null;
// 從建構函式注入訊息服務物件。
@huanlin
huanlin / MessageService
Created November 25, 2014 09:39
Unity Example 6-2
public interface IMessageService
{
void SendMessage(string to, string msg);
}
public class EmailService : IMessageService
{
public void SendMessage(string to, string msg)
{
Console.WriteLine(" 透過 EmailService 發送郵件給 {0}。", to);
@huanlin
huanlin / GetRuntimePropertyName
Last active August 29, 2015 14:15
Get property name at runtime.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
namespace ConsoleApplication1
{
class Program
@huanlin
huanlin / DemoAsync.csx
Last active April 23, 2016 10:52
ScriptCS Examples
public class DemoAsyncCall
{
public async Task ShowWebContent(string url)
{
var client = new HttpClient();
var response = await client.GetAsync(url);
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}
@huanlin
huanlin / ConfigWebGarden.csx
Last active April 28, 2016 18:01
Configure IIS Web Garden with Microsoft.Web.Administration
using System;
using System.Text;
using Microsoft.Web.Administration;
void SetWebGarden(string appPoolName, int maxProcesses)
{
ServerManager serverManager = new ServerManager();
ApplicationPoolCollection applicationPools = serverManager.ApplicationPools;
@huanlin
huanlin / porting-csproj-to-dotnet-core-2.0-step1.xml
Last active March 18, 2018 13:10
Porting csproj to .NET Core 2.0
<!-- 底下是準備要被替換的文字 -->
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B395A62E-B988-4370-AB66-D76A4FC49C9E}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>