/// <summary> /// This will return the portion of the URL to the left of the Mask token given. /// </summary> /// <param name="me">The Controller instance</param> /// <param name="Mask">The portion of the path directly after the service root base URL</param> /// <returns></returns> public static string CalculateBaseURI(this System.Web.Http.ApiController me, string Mask) { System.Uri ri = me.ControllerContext.Request.RequestUri; if (!String.IsNullOrWhiteSpace(Mask)) { string baseUri = System.String.Format("{0}://{1}{2}{3}{4}", ri.Scheme, ri.Host, ri.IsDefaultPort ? "" : ":" + ri.Port.ToString(), me.ControllerContext.RequestContext.VirtualPathRoot.TrimEnd('/') + '/', me.ControllerContext.RouteData.Route.RouteTemplate.Substring(0, me.ControllerContext.RouteData.Route.RouteTemplate.LastIndexOf(Mask))); return(baseUri.TrimEnd('/')); } else { //If the Mask is empty string then no need to strip off the end path string baseUri = System.String.Format("{0}://{1}{2}{3}{4}", ri.Scheme, ri.Host, ri.IsDefaultPort ? "" : ":" + ri.Port.ToString(), me.ControllerContext.RequestContext.VirtualPathRoot.TrimEnd('/') + '/', me.ControllerContext.RouteData.Route.RouteTemplate); return(baseUri.TrimEnd('/')); } }
public static string CalculateBaseURI(this System.Web.Http.ApiController me, string resourceName) { Uri ri = me.ControllerContext.Request.RequestUri; if (resourceName == "metadata" || resourceName == "${operation}") { return(String.Format("{0}://{1}{2}{3}{4}/", ri.Scheme, ri.Host, ri.IsDefaultPort ? "" : ":" + ri.Port.ToString(), me.ControllerContext.RequestContext.VirtualPathRoot.TrimEnd('/') + '/', me.ControllerContext.RouteData.Route.RouteTemplate.Replace("/metadata", "").Replace("/${operation}", ""))); } if (me.ControllerContext.RouteData.Route.RouteTemplate.Contains("{ResourceName}")) { resourceName = "{ResourceName}"; } string baseUri = String.Format("{0}://{1}{2}{3}{4}", ri.Scheme, ri.Host, ri.IsDefaultPort ? "" : ":" + ri.Port.ToString(), me.ControllerContext.RequestContext.VirtualPathRoot.TrimEnd('/') + '/', me.ControllerContext.RouteData.Route.RouteTemplate.Substring(0, me.ControllerContext.RouteData.Route.RouteTemplate.LastIndexOf(resourceName))); return(baseUri); }
public static string Resource(this System.Web.Http.ApiController controller, string name, params object[] args) { //コントローラーの名前からリソースのパスを生成する var fname = controller.GetType().FullName; fname = controller.GetType().FullName.Replace(RootNamespace + ".", ""); var cname = fname.Split('.').ToList(); var resourcePath = string.Format("{0}.{1}.{2}", RootNamespace, ResourcesRootFolderName, string.Join(".", cname)); return(GetString(resourcePath, name, args)); }
public static void MockCurrentUser(this System.Web.Http.ApiController controller, string userId, string username) { var identity = new GenericIdentity(username); identity.AddClaim( new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", username)); identity.AddClaim( new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", userId)); var principal = new GenericPrincipal(identity, null); controller.User = principal; //LD questo ".User" è una proprietà del controller, possiamo associare un user allo // specifico controller. }
public override void Handle(ExceptionHandlerContext context) { HttpControllerContext controllerContext = context.ExceptionContext.ControllerContext; if (controllerContext != null) { System.Web.Http.ApiController apiController = controllerContext.Controller as ApiController; if (apiController != null) { HttpActionContext actionContext = apiController.ActionContext; // ... } } // ... base.Handle(context); }
/// <summary> /// Gets the current Audit Scope. /// </summary> /// <param name="apiController">The API controller.</param> /// <returns>The current Audit Scope or NULL.</returns> /// <param name="contextWrapper">The context wrapper instance to use to provide the context. Default is NULL to use the default ContextWrapper.</param> public static AuditScope GetCurrentAuditScope(this System.Web.Http.ApiController apiController, IContextWrapper contextWrapper = null) { return(AuditApiAdapter.GetCurrentScope(apiController.Request, contextWrapper)); }
public static AuditScope GetCurrentAuditScope(this System.Web.Http.ApiController apiController) { return(AuditApiAttribute.GetCurrentScope(apiController.Request)); }
public OkJsonPatchResult(System.Web.Http.ApiController controller) : base(controller) { }
/// <summary> /// Get current client IP Address /// </summary> /// <param name="controller"></param> /// <returns></returns> public static string GetClientIpAddress(this System.Web.Http.ApiController controller) { return(controller == null ? string.Empty : GetClientIpAddress(controller.Request)); }