HttpRequestExtensions
Assembly: ServiceStack.dll
Declaration
public static class HttpRequestExtensions
Methods
GetItemOrCookie(IRequest, String)
Gets string value from Items[name] then Cookies[name] if exists.
Useful when first setting the users response cookie in the request filter.
To access the value for this initial request you need to set it in Items[].
Declaration
public static string GetItemOrCookie(this IRequest httpReq, string name)
Returns
System.String
: string value or null if it doesn't exist
Parameters
GetParam(IRequest, String)
Gets request parameter string value by looking in the following order:
- QueryString[name]
- FormData[name]
- Cookies[name]
- Items[name]
Declaration
public static string GetParam(this IRequest httpReq, string name)
Returns
System.String
: string value or null if it doesn't exist
Parameters
Declaration
public static string GetQueryStringOrForm(this IRequest httpReq, string name)
Returns
System.String
Parameters
GetParentAbsolutePath(IRequest)
Declaration
public static string GetParentAbsolutePath(this IRequest httpReq)
Returns
System.String
Parameters
GetAbsolutePath(IRequest)
Declaration
public static string GetAbsolutePath(this IRequest httpReq)
Returns
System.String
Parameters
GetParentPathUrl(IRequest)
Declaration
public static string GetParentPathUrl(this IRequest httpReq)
Returns
System.String
Parameters
GetPathUrl(IRequest)
Declaration
public static string GetPathUrl(this IRequest httpReq)
Returns
System.String
Parameters
GetUrlHostName(IRequest)
Declaration
public static string GetUrlHostName(this IRequest httpReq)
Returns
System.String
Parameters
GetPhysicalPath(IRequest)
Declaration
public static string GetPhysicalPath(this IRequest httpReq)
Returns
System.String
Parameters
GetVirtualNode(IRequest)
Declaration
public static IVirtualNode GetVirtualNode(this IRequest httpReq)
Returns
ServiceStack.IO.IVirtualNode
Parameters
GetDirectoryPath(IRequest)
Declaration
public static string GetDirectoryPath(this IRequest request)
Returns
System.String
Parameters
GetLeftAuthority(Uri)
Declaration
public static string GetLeftAuthority(this Uri uri)
Returns
System.String
Parameters
GetApplicationUrl(IRequest)
Declaration
public static string GetApplicationUrl(this IRequest httpReq)
Returns
System.String
Parameters
GetHttpMethodOverride(IRequest)
Declaration
public static string GetHttpMethodOverride(this IRequest httpReq)
Returns
System.String
Parameters
Declaration
public static string GetFormatModifier(this IRequest httpReq)
Returns
System.String
Parameters
HasNotModifiedSince(IRequest, Nullable<DateTime>)
Declaration
public static bool HasNotModifiedSince(this IRequest httpReq, DateTime? dateTime)
Returns
System.Boolean
Parameters
DidReturn304NotModified(IRequest, Nullable<DateTime>, IResponse)
Declaration
public static bool DidReturn304NotModified(this IRequest httpReq, DateTime? dateTime, IResponse httpRes)
Returns
System.Boolean
Parameters
GetJsonpCallback(IRequest)
Declaration
public static string GetJsonpCallback(this IRequest httpReq)
Returns
System.String
Parameters
CookiesAsDictionary(IRequest)
Declaration
public static Dictionary<string, string> CookiesAsDictionary(this IRequest httpReq)
Returns
System.Collections.Generic.Dictionary<System.String,System.String>
Parameters
ToStatusCode(Exception)
Declaration
public static int ToStatusCode(this Exception ex)
Returns
System.Int32
Parameters
Type | Name |
---|
System.Exception | ex |
ToErrorCode(Exception)
Declaration
public static string ToErrorCode(this Exception ex)
Returns
System.String
Parameters
Type | Name |
---|
System.Exception | ex |
ToWebServiceException(HttpError)
Declaration
public static WebServiceException ToWebServiceException(this HttpError error)
Returns
ServiceStack.WebServiceException
Parameters
ToWebServiceException(ValidationResult, Object, ValidationFeature)
Declaration
public static WebServiceException ToWebServiceException(this ValidationResult validationResult, object requestDto, ValidationFeature feature)
Returns
ServiceStack.WebServiceException
Parameters
GetOperationNameFromLastPathInfo(String)
Declaration
public static string GetOperationNameFromLastPathInfo(string lastPathInfo)
Returns
System.String
Parameters
Type | Name |
---|
System.String | lastPathInfo |
GetParentBaseUrl(IRequest)
Declaration
public static string GetParentBaseUrl(this IRequest request)
Returns
System.String
Parameters
SanitizedVirtualPath(String)
Declaration
public static string SanitizedVirtualPath(this string virtualPath)
Returns
System.String
Parameters
Type | Name |
---|
System.String | virtualPath |
GetParentBaseUrl(HttpRequestBase)
Declaration
public static string GetParentBaseUrl(this HttpRequestBase request)
Returns
System.String
Parameters
Type | Name |
---|
System.Web.HttpRequestBase | request |
GetApplicationUrl(HttpRequestBase)
Declaration
public static string GetApplicationUrl(this HttpRequestBase httpReq)
Returns
System.String
Parameters
Type | Name |
---|
System.Web.HttpRequestBase | httpReq |
GetBaseUrl(HttpRequestBase)
Declaration
public static string GetBaseUrl(this HttpRequestBase request)
Returns
System.String
Parameters
Type | Name |
---|
System.Web.HttpRequestBase | request |
GetUrlHostName(HttpRequestBase)
Declaration
public static string GetUrlHostName(this HttpRequestBase request)
Returns
System.String
Parameters
Type | Name |
---|
System.Web.HttpRequestBase | request |
GetLastPathInfo(HttpRequestBase)
Declaration
public static string GetLastPathInfo(this HttpRequestBase request)
Returns
System.String
Parameters
Type | Name |
---|
System.Web.HttpRequestBase | request |
GetOperationName(HttpRequestBase)
Declaration
public static string GetOperationName(this HttpRequestBase request)
Returns
System.String
Parameters
Type | Name |
---|
System.Web.HttpRequestBase | request |
GetOperationName(HttpListenerRequest)
Declaration
public static string GetOperationName(this HttpListenerRequest request)
Returns
System.String
Parameters
Type | Name |
---|
System.Net.HttpListenerRequest | request |
GetLastPathInfo(HttpListenerRequest)
Declaration
public static string GetLastPathInfo(this HttpListenerRequest request)
Returns
System.String
Parameters
Type | Name |
---|
System.Net.HttpListenerRequest | request |
GetPathInfo(String, String, String)
Declaration
public static string GetPathInfo(string fullPath, string mode, string appPath)
Returns
System.String
Parameters
Type | Name |
---|
System.String | fullPath |
System.String | mode |
System.String | appPath |
ResolvePathInfoFromMappedPath(String, String)
Declaration
public static string ResolvePathInfoFromMappedPath(string fullPath, string mappedPathRoot)
Returns
System.String
Parameters
Type | Name |
---|
System.String | fullPath |
System.String | mappedPathRoot |
IsContentType(IRequest, String)
Declaration
public static bool IsContentType(this IRequest request, string contentType)
Returns
System.Boolean
Parameters
HasAnyOfContentTypes(IRequest, String[])
Declaration
public static bool HasAnyOfContentTypes(this IRequest request, params string[] contentTypes)
Returns
System.Boolean
Parameters
GetFlattenedRequestParams(IRequest)
Duplicate params have their values joined together in a comma-delimited string
Declaration
public static Dictionary<string, string> GetFlattenedRequestParams(this IRequest request)
Returns
System.Collections.Generic.Dictionary<System.String,System.String>
Parameters
GetQueryStringContentType(IRequest)
Declaration
public static string GetQueryStringContentType(this IRequest httpReq)
Returns
System.String
Parameters
ResolveItem(IRequest, String, Func<IRequest, Object>)
Use this to treat Request.Items[] as a cache by returning pre-computed items to save
calculating them multiple times.
Declaration
public static object ResolveItem(this IRequest httpReq, string itemKey, Func<IRequest, object> resolveFn)
Returns
System.Object
Parameters
GetResponseContentType(IRequest)
Declaration
public static string GetResponseContentType(this IRequest httpReq)
Returns
System.String
Parameters
SetView(IRequest, String)
Declaration
public static void SetView(this IRequest httpReq, string viewName)
Parameters
GetView(IRequest)
Declaration
public static string GetView(this IRequest httpReq)
Returns
System.String
Parameters
SetErrorView(IRequest, String)
Specify the View to render HTML error responses with
Declaration
public static void SetErrorView(this IRequest httpReq, string viewName)
Parameters
GetErrorView(IRequest)
Get the View to render HTML error responses with
Declaration
public static string GetErrorView(this IRequest httpReq)
Returns
System.String
Parameters
SetTemplate(IRequest, String)
Declaration
public static void SetTemplate(this IRequest httpReq, string templateName)
Parameters
GetTemplate(IRequest)
Declaration
public static string GetTemplate(this IRequest httpReq)
Returns
System.String
Parameters
ResolveAbsoluteUrl(IRequest, String)
Declaration
public static string ResolveAbsoluteUrl(this IRequest httpReq, string virtualPath = null)
Returns
System.String
Parameters
GetRawUrl(IRequest)
Declaration
public static string GetRawUrl(this IRequest httpReq)
Returns
System.String
Parameters
GetAbsoluteUrl(IRequest, String)
Declaration
public static string GetAbsoluteUrl(this IRequest httpReq, string url)
Returns
System.String
Parameters
GetReturnUrl(IRequest)
Declaration
public static string GetReturnUrl(this IRequest req)
Returns
System.String
Parameters
InferBaseUrl(String, String)
Declaration
public static string InferBaseUrl(this string absoluteUri, string fromPathInfo = null)
Returns
System.String
Parameters
Type | Name |
---|
System.String | absoluteUri |
System.String | fromPathInfo |
GetBaseUrl(IRequest)
Declaration
public static string GetBaseUrl(this IRequest httpReq)
Returns
System.String
Parameters
UseHttps(IRequest)
Declaration
public static bool UseHttps(this IRequest httpReq)
Returns
System.Boolean
Parameters
NormalizeScheme(String, Boolean)
Declaration
public static string NormalizeScheme(this string url, bool useHttps)
Returns
System.String
Parameters
Type | Name |
---|
System.String | url |
System.Boolean | useHttps |
ToRequestAttributes(String[])
Declaration
public static RequestAttributes ToRequestAttributes(string[] attrNames)
Returns
ServiceStack.RequestAttributes
Parameters
Type | Name |
---|
System.String[] | attrNames |
GetAttributes(IRequest)
Declaration
public static RequestAttributes GetAttributes(this IRequest request)
Returns
ServiceStack.RequestAttributes
Parameters
GetAttributes(IPAddress)
Declaration
public static RequestAttributes GetAttributes(IPAddress ipAddress)
Returns
ServiceStack.RequestAttributes
Parameters
Type | Name |
---|
System.Net.IPAddress | ipAddress |
IsInLocalSubnet(IPAddress)
Declaration
public static bool IsInLocalSubnet(this IPAddress ipAddress)
Returns
System.Boolean
Parameters
Type | Name |
---|
System.Net.IPAddress | ipAddress |
ToRequestContext(IRequest)
Declaration
public static RequestContext ToRequestContext(this IRequest req)
Returns
System.Web.Routing.RequestContext
Parameters
ToHttpContextBase(IRequest)
Declaration
public static HttpContextBase ToHttpContextBase(this IRequest req)
Returns
System.Web.HttpContextBase
Parameters
ToHttpResponseBase(IResponse)
Declaration
public static HttpResponseBase ToHttpResponseBase(this IResponse res)
Returns
System.Web.HttpResponseBase
Parameters
ToHttpContextBase(HttpRequestBase)
Declaration
public static HttpContextBase ToHttpContextBase(this HttpRequestBase aspnetHttpReq)
Returns
System.Web.HttpContextBase
Parameters
Type | Name |
---|
System.Web.HttpRequestBase | aspnetHttpReq |
ToHttpContextBase(HttpContext)
Declaration
public static HttpContextBase ToHttpContextBase(this HttpContext httpContext)
Returns
System.Web.HttpContextBase
Parameters
Type | Name |
---|
System.Web.HttpContext | httpContext |
ToRequest(HttpContext, String)
Declaration
public static IHttpRequest ToRequest(this HttpContext httpCtx, string operationName = null)
Returns
ServiceStack.Web.IHttpRequest
Parameters
Type | Name |
---|
System.Web.HttpContext | httpCtx |
System.String | operationName |
ToRequest(HttpContextBase, String)
Declaration
public static IHttpRequest ToRequest(this HttpContextBase httpCtx, string operationName = null)
Returns
ServiceStack.Web.IHttpRequest
Parameters
Type | Name |
---|
System.Web.HttpContextBase | httpCtx |
System.String | operationName |
ToRequest(HttpRequestBase, String)
Declaration
public static IHttpRequest ToRequest(this HttpRequestBase httpCtx, string operationName = null)
Returns
ServiceStack.Web.IHttpRequest
Parameters
Type | Name |
---|
System.Web.HttpRequestBase | httpCtx |
System.String | operationName |
ToRequest(HttpListenerContext, String)
Declaration
public static IHttpRequest ToRequest(this HttpListenerContext httpCtxReq, string operationName = null)
Returns
ServiceStack.Web.IHttpRequest
Parameters
Type | Name |
---|
System.Net.HttpListenerContext | httpCtxReq |
System.String | operationName |
ToResponse(HttpContext)
Declaration
public static IHttpResponse ToResponse(this HttpContext httpCtx)
Returns
ServiceStack.Web.IHttpResponse
Parameters
Type | Name |
---|
System.Web.HttpContext | httpCtx |
ToResponse(HttpRequestBase)
Declaration
public static IHttpResponse ToResponse(this HttpRequestBase aspReq)
Returns
ServiceStack.Web.IHttpResponse
Parameters
Type | Name |
---|
System.Web.HttpRequestBase | aspReq |
ToResponse(HttpListenerContext)
Declaration
public static IHttpResponse ToResponse(this HttpListenerContext httpCtx)
Returns
ServiceStack.Web.IHttpResponse
Parameters
Type | Name |
---|
System.Net.HttpListenerContext | httpCtx |
GetSoapMessage(IRequest)
Declaration
public static Message GetSoapMessage(this IRequest httpReq)
Returns
System.ServiceModel.Channels.Message
Parameters
GetPathAndQuery(HttpRequestBase)
Declaration
public static string GetPathAndQuery(this HttpRequestBase request)
Returns
System.String
Parameters
Type | Name |
---|
System.Web.HttpRequestBase | request |
GetOperationType(IRequest)
Declaration
public static Type GetOperationType(this IRequest req)
Returns
System.Type
Parameters
IsMultiRequest(IRequest)
Declaration
public static bool IsMultiRequest(this IRequest req)
Returns
System.Boolean
Parameters
Declaration
public static void SetAutoBatchCompletedHeader(this IRequest req, int completed)
Parameters
SetRoute(IRequest, RestPath)
Declaration
public static void SetRoute(this IRequest req, RestPath route)
Parameters
GetRoute(IRequest)
Declaration
public static RestPath GetRoute(this IRequest req)
Returns
ServiceStack.Host.RestPath
Parameters
IsHtml(IRequest)
Declaration
public static bool IsHtml(this IRequest req)
Returns
System.Boolean
Parameters
GetRequestValue(IHttpRequest, String)
Declaration
public static string GetRequestValue(this IHttpRequest req, string name)
Returns
System.String
Parameters
EachRequest<T>(IRequest, Action<T>)
Declaration
public static void EachRequest<T>(this IRequest httpReq, Action<T> action)
Parameters
Type Parameters
GetClaimsPrincipal(IRequest)
Declaration
public static ClaimsPrincipal GetClaimsPrincipal(this IRequest req)
Returns
System.Security.Claims.ClaimsPrincipal
Parameters
GetClaims(IRequest)
Declaration
public static IEnumerable<Claim> GetClaims(this IRequest req)
Returns
System.Collections.Generic.IEnumerable<System.Security.Claims.Claim>
Parameters
HasRole(IEnumerable<Claim>, String)
Declaration
public static bool HasRole(this IEnumerable<Claim> claims, string role)
Returns
System.Boolean
Parameters
Type | Name |
---|
System.Collections.Generic.IEnumerable<System.Security.Claims.Claim> | claims |
System.String | role |
HasScope(IEnumerable<Claim>, String)
Declaration
public static bool HasScope(this IEnumerable<Claim> claims, string scope)
Returns
System.Boolean
Parameters
Type | Name |
---|
System.Collections.Generic.IEnumerable<System.Security.Claims.Claim> | claims |
System.String | scope |
HasClaim(IEnumerable<Claim>, String, String)
Declaration
public static bool HasClaim(this IEnumerable<Claim> claims, string type, string value)
Returns
System.Boolean
Parameters
Type | Name |
---|
System.Collections.Generic.IEnumerable<System.Security.Claims.Claim> | claims |
System.String | type |
System.String | value |
CanReadRequestBody(IRequest)
Declaration
public static bool CanReadRequestBody(this IRequest req)
Returns
System.Boolean
Parameters