Skip to main content

HttpRequestExtensions

Assembly: ServiceStack.dll
View Source
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[].

View Source
Declaration
public static string GetItemOrCookie(this IRequest httpReq, string name)
Returns

System.String: string value or null if it doesn't exist

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq
System.Stringname

GetParam(IRequest, String)

Gets request parameter string value by looking in the following order:

  • QueryString[name]
  • FormData[name]
  • Cookies[name]
  • Items[name]
View Source
Declaration
public static string GetParam(this IRequest httpReq, string name)
Returns

System.String: string value or null if it doesn't exist

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq
System.Stringname

GetQueryStringOrForm(IRequest, String)

View Source
Declaration
public static string GetQueryStringOrForm(this IRequest httpReq, string name)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq
System.Stringname

GetParentAbsolutePath(IRequest)

View Source
Declaration
public static string GetParentAbsolutePath(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

GetAbsolutePath(IRequest)

View Source
Declaration
public static string GetAbsolutePath(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

GetParentPathUrl(IRequest)

View Source
Declaration
public static string GetParentPathUrl(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

GetPathUrl(IRequest)

View Source
Declaration
public static string GetPathUrl(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

GetUrlHostName(IRequest)

View Source
Declaration
public static string GetUrlHostName(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

GetPhysicalPath(IRequest)

View Source
Declaration
public static string GetPhysicalPath(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

GetVirtualNode(IRequest)

View Source
Declaration
public static IVirtualNode GetVirtualNode(this IRequest httpReq)
Returns

ServiceStack.IO.IVirtualNode

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

GetDirectoryPath(IRequest)

View Source
Declaration
public static string GetDirectoryPath(this IRequest request)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequestrequest

GetLeftAuthority(Uri)

View Source
Declaration
public static string GetLeftAuthority(this Uri uri)
Returns

System.String

Parameters
TypeName
System.Uriuri

GetApplicationUrl(IRequest)

View Source
Declaration
public static string GetApplicationUrl(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

GetHttpMethodOverride(IRequest)

View Source
Declaration
public static string GetHttpMethodOverride(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

GetFormatModifier(IRequest)

View Source
Declaration
public static string GetFormatModifier(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

HasNotModifiedSince(IRequest, Nullable<DateTime>)

View Source
Declaration
public static bool HasNotModifiedSince(this IRequest httpReq, DateTime? dateTime)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq
System.Nullable<System.DateTime>dateTime

DidReturn304NotModified(IRequest, Nullable<DateTime>, IResponse)

View Source
Declaration
public static bool DidReturn304NotModified(this IRequest httpReq, DateTime? dateTime, IResponse httpRes)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq
System.Nullable<System.DateTime>dateTime
ServiceStack.Web.IResponsehttpRes

GetJsonpCallback(IRequest)

View Source
Declaration
public static string GetJsonpCallback(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

CookiesAsDictionary(IRequest)

View Source
Declaration
public static Dictionary<string, string> CookiesAsDictionary(this IRequest httpReq)
Returns

System.Collections.Generic.Dictionary<System.String,System.String>

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

ToStatusCode(Exception)

View Source
Declaration
public static int ToStatusCode(this Exception ex)
Returns

System.Int32

Parameters
TypeName
System.Exceptionex

ToErrorCode(Exception)

View Source
Declaration
public static string ToErrorCode(this Exception ex)
Returns

System.String

Parameters
TypeName
System.Exceptionex

ToWebServiceException(HttpError)

View Source
Declaration
public static WebServiceException ToWebServiceException(this HttpError error)
Returns

ServiceStack.WebServiceException

Parameters
TypeName
ServiceStack.HttpErrorerror

ToWebServiceException(ValidationResult, Object, ValidationFeature)

View Source
Declaration
public static WebServiceException ToWebServiceException(this ValidationResult validationResult, object requestDto, ValidationFeature feature)
Returns

ServiceStack.WebServiceException

Parameters
TypeName
ServiceStack.FluentValidation.Results.ValidationResultvalidationResult
System.ObjectrequestDto
ServiceStack.Validation.ValidationFeaturefeature

GetOperationNameFromLastPathInfo(String)

View Source
Declaration
public static string GetOperationNameFromLastPathInfo(string lastPathInfo)
Returns

System.String

Parameters
TypeName
System.StringlastPathInfo

GetParentBaseUrl(IRequest)

View Source
Declaration
public static string GetParentBaseUrl(this IRequest request)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequestrequest

SanitizedVirtualPath(String)

View Source
Declaration
public static string SanitizedVirtualPath(this string virtualPath)
Returns

System.String

Parameters
TypeName
System.StringvirtualPath

GetParentBaseUrl(HttpRequestBase)

View Source
Declaration
public static string GetParentBaseUrl(this HttpRequestBase request)
Returns

System.String

Parameters
TypeName
System.Web.HttpRequestBaserequest

GetApplicationUrl(HttpRequestBase)

View Source
Declaration
public static string GetApplicationUrl(this HttpRequestBase httpReq)
Returns

System.String

Parameters
TypeName
System.Web.HttpRequestBasehttpReq

GetBaseUrl(HttpRequestBase)

View Source
Declaration
public static string GetBaseUrl(this HttpRequestBase request)
Returns

System.String

Parameters
TypeName
System.Web.HttpRequestBaserequest

GetUrlHostName(HttpRequestBase)

View Source
Declaration
public static string GetUrlHostName(this HttpRequestBase request)
Returns

System.String

Parameters
TypeName
System.Web.HttpRequestBaserequest

GetLastPathInfo(HttpRequestBase)

View Source
Declaration
public static string GetLastPathInfo(this HttpRequestBase request)
Returns

System.String

Parameters
TypeName
System.Web.HttpRequestBaserequest

GetOperationName(HttpRequestBase)

View Source
Declaration
public static string GetOperationName(this HttpRequestBase request)
Returns

System.String

Parameters
TypeName
System.Web.HttpRequestBaserequest

GetOperationName(HttpListenerRequest)

View Source
Declaration
public static string GetOperationName(this HttpListenerRequest request)
Returns

System.String

Parameters
TypeName
System.Net.HttpListenerRequestrequest

GetLastPathInfo(HttpListenerRequest)

View Source
Declaration
public static string GetLastPathInfo(this HttpListenerRequest request)
Returns

System.String

Parameters
TypeName
System.Net.HttpListenerRequestrequest

GetPathInfo(String, String, String)

View Source
Declaration
public static string GetPathInfo(string fullPath, string mode, string appPath)
Returns

System.String

Parameters
TypeName
System.StringfullPath
System.Stringmode
System.StringappPath

ResolvePathInfoFromMappedPath(String, String)

View Source
Declaration
public static string ResolvePathInfoFromMappedPath(string fullPath, string mappedPathRoot)
Returns

System.String

Parameters
TypeName
System.StringfullPath
System.StringmappedPathRoot

IsContentType(IRequest, String)

View Source
Declaration
public static bool IsContentType(this IRequest request, string contentType)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequestrequest
System.StringcontentType

HasAnyOfContentTypes(IRequest, String[])

View Source
Declaration
public static bool HasAnyOfContentTypes(this IRequest request, params string[] contentTypes)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequestrequest
System.String[]contentTypes

GetFlattenedRequestParams(IRequest)

Duplicate params have their values joined together in a comma-delimited string

View Source
Declaration
public static Dictionary<string, string> GetFlattenedRequestParams(this IRequest request)
Returns

System.Collections.Generic.Dictionary<System.String,System.String>

Parameters
TypeName
ServiceStack.Web.IRequestrequest

GetQueryStringContentType(IRequest)

View Source
Declaration
public static string GetQueryStringContentType(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

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.

View Source
Declaration
public static object ResolveItem(this IRequest httpReq, string itemKey, Func<IRequest, object> resolveFn)
Returns

System.Object

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq
System.StringitemKey
System.Func<ServiceStack.Web.IRequest,System.Object>resolveFn

GetResponseContentType(IRequest)

View Source
Declaration
public static string GetResponseContentType(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

SetView(IRequest, String)

View Source
Declaration
public static void SetView(this IRequest httpReq, string viewName)
Parameters
TypeName
ServiceStack.Web.IRequesthttpReq
System.StringviewName

GetView(IRequest)

View Source
Declaration
public static string GetView(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

SetErrorView(IRequest, String)

Specify the View to render HTML error responses with

View Source
Declaration
public static void SetErrorView(this IRequest httpReq, string viewName)
Parameters
TypeName
ServiceStack.Web.IRequesthttpReq
System.StringviewName

GetErrorView(IRequest)

Get the View to render HTML error responses with

View Source
Declaration
public static string GetErrorView(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

SetTemplate(IRequest, String)

View Source
Declaration
public static void SetTemplate(this IRequest httpReq, string templateName)
Parameters
TypeName
ServiceStack.Web.IRequesthttpReq
System.StringtemplateName

GetTemplate(IRequest)

View Source
Declaration
public static string GetTemplate(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

ResolveAbsoluteUrl(IRequest, String)

View Source
Declaration
public static string ResolveAbsoluteUrl(this IRequest httpReq, string virtualPath = null)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq
System.StringvirtualPath

GetRawUrl(IRequest)

View Source
Declaration
public static string GetRawUrl(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

GetAbsoluteUrl(IRequest, String)

View Source
Declaration
public static string GetAbsoluteUrl(this IRequest httpReq, string url)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq
System.Stringurl

GetReturnUrl(IRequest)

View Source
Declaration
public static string GetReturnUrl(this IRequest req)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequestreq

InferBaseUrl(String, String)

View Source
Declaration
public static string InferBaseUrl(this string absoluteUri, string fromPathInfo = null)
Returns

System.String

Parameters
TypeName
System.StringabsoluteUri
System.StringfromPathInfo

GetBaseUrl(IRequest)

View Source
Declaration
public static string GetBaseUrl(this IRequest httpReq)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

UseHttps(IRequest)

View Source
Declaration
public static bool UseHttps(this IRequest httpReq)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

NormalizeScheme(String, Boolean)

View Source
Declaration
public static string NormalizeScheme(this string url, bool useHttps)
Returns

System.String

Parameters
TypeName
System.Stringurl
System.BooleanuseHttps

ToRequestAttributes(String[])

View Source
Declaration
public static RequestAttributes ToRequestAttributes(string[] attrNames)
Returns

ServiceStack.RequestAttributes

Parameters
TypeName
System.String[]attrNames

GetAttributes(IRequest)

View Source
Declaration
public static RequestAttributes GetAttributes(this IRequest request)
Returns

ServiceStack.RequestAttributes

Parameters
TypeName
ServiceStack.Web.IRequestrequest

GetAttributes(IPAddress)

View Source
Declaration
public static RequestAttributes GetAttributes(IPAddress ipAddress)
Returns

ServiceStack.RequestAttributes

Parameters
TypeName
System.Net.IPAddressipAddress

IsInLocalSubnet(IPAddress)

View Source
Declaration
public static bool IsInLocalSubnet(this IPAddress ipAddress)
Returns

System.Boolean

Parameters
TypeName
System.Net.IPAddressipAddress

ToRequestContext(IRequest)

View Source
Declaration
public static RequestContext ToRequestContext(this IRequest req)
Returns

System.Web.Routing.RequestContext

Parameters
TypeName
ServiceStack.Web.IRequestreq

ToHttpContextBase(IRequest)

View Source
Declaration
public static HttpContextBase ToHttpContextBase(this IRequest req)
Returns

System.Web.HttpContextBase

Parameters
TypeName
ServiceStack.Web.IRequestreq

ToHttpResponseBase(IResponse)

View Source
Declaration
public static HttpResponseBase ToHttpResponseBase(this IResponse res)
Returns

System.Web.HttpResponseBase

Parameters
TypeName
ServiceStack.Web.IResponseres

ToHttpContextBase(HttpRequestBase)

View Source
Declaration
public static HttpContextBase ToHttpContextBase(this HttpRequestBase aspnetHttpReq)
Returns

System.Web.HttpContextBase

Parameters
TypeName
System.Web.HttpRequestBaseaspnetHttpReq

ToHttpContextBase(HttpContext)

View Source
Declaration
public static HttpContextBase ToHttpContextBase(this HttpContext httpContext)
Returns

System.Web.HttpContextBase

Parameters
TypeName
System.Web.HttpContexthttpContext

ToRequest(HttpContext, String)

View Source
Declaration
public static IHttpRequest ToRequest(this HttpContext httpCtx, string operationName = null)
Returns

ServiceStack.Web.IHttpRequest

Parameters
TypeName
System.Web.HttpContexthttpCtx
System.StringoperationName

ToRequest(HttpContextBase, String)

View Source
Declaration
public static IHttpRequest ToRequest(this HttpContextBase httpCtx, string operationName = null)
Returns

ServiceStack.Web.IHttpRequest

Parameters
TypeName
System.Web.HttpContextBasehttpCtx
System.StringoperationName

ToRequest(HttpRequestBase, String)

View Source
Declaration
public static IHttpRequest ToRequest(this HttpRequestBase httpCtx, string operationName = null)
Returns

ServiceStack.Web.IHttpRequest

Parameters
TypeName
System.Web.HttpRequestBasehttpCtx
System.StringoperationName

ToRequest(HttpListenerContext, String)

View Source
Declaration
public static IHttpRequest ToRequest(this HttpListenerContext httpCtxReq, string operationName = null)
Returns

ServiceStack.Web.IHttpRequest

Parameters
TypeName
System.Net.HttpListenerContexthttpCtxReq
System.StringoperationName

ToResponse(HttpContext)

View Source
Declaration
public static IHttpResponse ToResponse(this HttpContext httpCtx)
Returns

ServiceStack.Web.IHttpResponse

Parameters
TypeName
System.Web.HttpContexthttpCtx

ToResponse(HttpRequestBase)

View Source
Declaration
public static IHttpResponse ToResponse(this HttpRequestBase aspReq)
Returns

ServiceStack.Web.IHttpResponse

Parameters
TypeName
System.Web.HttpRequestBaseaspReq

ToResponse(HttpListenerContext)

View Source
Declaration
public static IHttpResponse ToResponse(this HttpListenerContext httpCtx)
Returns

ServiceStack.Web.IHttpResponse

Parameters
TypeName
System.Net.HttpListenerContexthttpCtx

GetSoapMessage(IRequest)

View Source
Declaration
public static Message GetSoapMessage(this IRequest httpReq)
Returns

System.ServiceModel.Channels.Message

Parameters
TypeName
ServiceStack.Web.IRequesthttpReq

GetPathAndQuery(HttpRequestBase)

View Source
Declaration
public static string GetPathAndQuery(this HttpRequestBase request)
Returns

System.String

Parameters
TypeName
System.Web.HttpRequestBaserequest

GetOperationType(IRequest)

View Source
Declaration
public static Type GetOperationType(this IRequest req)
Returns

System.Type

Parameters
TypeName
ServiceStack.Web.IRequestreq

IsMultiRequest(IRequest)

View Source
Declaration
public static bool IsMultiRequest(this IRequest req)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequestreq

SetAutoBatchCompletedHeader(IRequest, Int32)

View Source
Declaration
public static void SetAutoBatchCompletedHeader(this IRequest req, int completed)
Parameters
TypeName
ServiceStack.Web.IRequestreq
System.Int32completed

SetRoute(IRequest, RestPath)

View Source
Declaration
public static void SetRoute(this IRequest req, RestPath route)
Parameters
TypeName
ServiceStack.Web.IRequestreq
ServiceStack.Host.RestPathroute

GetRoute(IRequest)

View Source
Declaration
public static RestPath GetRoute(this IRequest req)
Returns

ServiceStack.Host.RestPath

Parameters
TypeName
ServiceStack.Web.IRequestreq

IsHtml(IRequest)

View Source
Declaration
public static bool IsHtml(this IRequest req)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequestreq

GetRequestValue(IHttpRequest, String)

View Source
Declaration
public static string GetRequestValue(this IHttpRequest req, string name)
Returns

System.String

Parameters
TypeName
ServiceStack.Web.IHttpRequestreq
System.Stringname

EachRequest<T>(IRequest, Action<T>)

View Source
Declaration
public static void EachRequest<T>(this IRequest httpReq, Action<T> action)
Parameters
TypeName
ServiceStack.Web.IRequesthttpReq
System.Action<<T>>action
Type Parameters
  • T

GetClaimsPrincipal(IRequest)

View Source
Declaration
public static ClaimsPrincipal GetClaimsPrincipal(this IRequest req)
Returns

System.Security.Claims.ClaimsPrincipal

Parameters
TypeName
ServiceStack.Web.IRequestreq

GetClaims(IRequest)

View Source
Declaration
public static IEnumerable<Claim> GetClaims(this IRequest req)
Returns

System.Collections.Generic.IEnumerable<System.Security.Claims.Claim>

Parameters
TypeName
ServiceStack.Web.IRequestreq

HasRole(IEnumerable<Claim>, String)

View Source
Declaration
public static bool HasRole(this IEnumerable<Claim> claims, string role)
Returns

System.Boolean

Parameters
TypeName
System.Collections.Generic.IEnumerable<System.Security.Claims.Claim>claims
System.Stringrole

HasScope(IEnumerable<Claim>, String)

View Source
Declaration
public static bool HasScope(this IEnumerable<Claim> claims, string scope)
Returns

System.Boolean

Parameters
TypeName
System.Collections.Generic.IEnumerable<System.Security.Claims.Claim>claims
System.Stringscope

HasClaim(IEnumerable<Claim>, String, String)

View Source
Declaration
public static bool HasClaim(this IEnumerable<Claim> claims, string type, string value)
Returns

System.Boolean

Parameters
TypeName
System.Collections.Generic.IEnumerable<System.Security.Claims.Claim>claims
System.Stringtype
System.Stringvalue

CanReadRequestBody(IRequest)

View Source
Declaration
public static bool CanReadRequestBody(this IRequest req)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequestreq