StringExtensions

Namespace: ASPSecurityKit
Assembly: ASPSecurityKit.dll

Summary

Static string extension methods for general, reusable utility operations.

Methods

Format(text,args)

Summary

Gets a formatted string value using the specified arguments.

Returns

A formatted string value using the specified arguments.

Parameters
Name Type Description
text System.String The text to format.
args System.Object[] The arguments.

RemoveQueryParam(url,paramName)

Summary

Removes the query parameter (if exists) from the specified URL.

Returns

The URL without the specified query parameter.

Parameters
Name Type Description
url System.String The URL.
paramName System.String Name of the parameter.

InIpRange(ip,beginIp,endIp)

Summary

Determines whether the given IP address is in the specified IP range.

Returns

true if the given IP address is in the specified IP range; otherwise, false.

Parameters
Name Type Description
ip System.String The IP address to validate.
beginIp System.String Indicates the starting IP address of the range.
endIp System.String Indicates the last IP address of the range.

CompareIp(thisIp,thatIp)

Summary

Compares thisIp address with thatIp and returns an integer that indicates whether thisIp precedes, follows, or occurs in the same position in the sort order as thatIp.

Returns

A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero ThisIp precedes thatIp in the sort order. Zero ThisIp occurs in the same position in the sort order as thatIp. Greater than zero ThisIp follows thatIp in the sort order.

Parameters
Name Type Description
thisIp System.String The IP address being compared.
thatIp System.String The IP address to compared with.
Exceptions
Type Description
System.InvalidOperationException When both the IPs do not belong to the same address family.

ToIpBigInt(ip)

Summary

Converts the specified IP address to a BigInteger instance.

Returns

A BigInteger instance representing the specified IP address.

Parameters
Name Type Description
ip System.String The IP address to convert.

ComputeHmacSignatureString(data,secret,algorithm)

Summary

Gets an HMAC computed for the given data using the specified secret and algorithm. Use one of the algorithms as defined by HashAlgorithmName.

Returns

An HMAC hash as string.

Parameters
Name Type Description
data System.String The data for which HMAC is to be computed.
secret System.String The secret.
algorithm ASPSecurityKit.HashAlgorithmName The algorithm.

ToUri(src)

Summary

Converts the given string to a Uri instance. Returns null if conversion didn’t succeed.

Returns

A Uri instance if conversion succeeded; otherwise, null.

Parameters
Name Type Description
src System.String The source string to convert.

ComputeHash(data,algorithm)

Summary

Gets a hash computed for the given data using the specified algorithm. Use one of the algorithms as defined by HashAlgorithmName type.

Returns

The hash as array of bytes.

Parameters
Name Type Description
data System.String The data for which hash is to be computed.
algorithm ASPSecurityKit.HashAlgorithmName The algorithm.

ComputeHashString(data,algorithm)

Summary

Gets a hash computed for the given data using the specified algorithm. Use one of the algorithms as defined by HashAlgorithmName type.

Returns

The hash as base64 encoded string.

Parameters
Name Type Description
data System.String The data for which hash is to be computed.
algorithm ASPSecurityKit.HashAlgorithmName The algorithm.

IsURLSimilarTo(currentUrl,otherUrl)

Summary

Determines whether the current URL is same as the other URL.

Returns

true if the current URL is same as the other URL; otherwise, false.

Parameters
Name Type Description
currentUrl System.String The current URL; must be absolute URI.
otherUrl System.String The other URL; could be relative ('/User/SignIn', for example,) URI.
Exceptions
Type Description
System.ArgumentException when currentUrl is not an absolute URL.
Remarks

If the otherUrl is relative ('/User/SignIn', for example,) the SchemeAndServer components of currentUrl are joined with it to make it absolute. Sameness is determined by checking whether the currentUrl matches with otherUrl for the following components: SchemeAndServer and Path.