リクエストの送信元の IP アドレスを保存するアプリを作成しています。これらの IP アドレスはvarbinary(16)
データベースに として保存されます。varbinary(16)
aが適切なサイズではないことが明らかになりました。現在、次のコードを使用して、リクエストの IP アドレスを byte[]; に取得しています。
HttpRequestMessage request = GetRequestMessage();
string ipAddress = string.Empty;
if (request.Properties.ContainsKey("MS_HttpContext"))
{
ipAddress = ((HttpContextWrapper)request.Properties["MS_HttpContext"]).Request.UserHostAddress;
}
else if (request.Properties.ContainsKey(RemoteEndpointMessageProperty.Name))
{
RemoteEndpointMessageProperty property = (RemoteEndpointMessageProperty)request.Properties[RemoteEndpointMessageProperty.Name];
ipAddress = property.Address;
}
byte[] bytes = new byte[ipAddress.Length * sizeof(char)];
System.Buffer.BlockCopy(ipAddress.ToCharArray(), 0, bytes, 0, bytes.Length);
// What is the maximum size of bytes?
バイトの長さが 26 であることに気付きました。私の質問は、IPv6 アドレスをサポートする必要がある場合、バイトの最大サイズはどれくらいですか? varbinary(16)
のサイズを適切な長さに変更する方法を知る必要があります。
ありがとうございました!