/// <summary> /// If the request path starts with the given pathMatch, execute the app configured via configuration parameter instead of /// continuing to the next component in the pipeline. /// </summary> /// <param name="app"></param> /// <param name="pathMatch">The path to match</param> /// <param name="configuration">The branch to take for positive path matches</param> /// <returns></returns> public static IAppBuilder Map(this IAppBuilder app, PathString pathMatch, Action<IAppBuilder> configuration) { if (app == null) { throw new ArgumentNullException("app"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } if (pathMatch.HasValue && pathMatch.Value.EndsWith("/", StringComparison.Ordinal)) { throw new ArgumentException(Resources.Exception_PathMustNotEndWithSlash, "pathMatch"); } // put middleware in pipeline before creating branch var options = new MapOptions { PathMatch = pathMatch }; IAppBuilder result = app.Use<MapMiddleware>(options); // create branch and assign to options IAppBuilder branch = app.New(); configuration(branch); options.Branch = (AppFunc)branch.Build(typeof(AppFunc)); return result; }
/// <summary> /// Initializes a new instance of the <see cref="MapMiddleware"/> class /// </summary> /// <param name="next">The normal pipeline taken for a negative match</param> /// <param name="options"></param> public MapMiddleware(OwinMiddleware next, MapOptions options) : base(next) { if (next == null) { throw new ArgumentNullException("next"); } if (options == null) { throw new ArgumentNullException("options"); } if (options.PathMatch == null) { throw new ArgumentException(Resources.Exception_PathRequired); } _options = options; }
/// <summary> /// Initializes a new instance of the <see cref="MapMiddleware"/> class /// </summary> /// <param name="next">The normal pipeline taken for a negative match</param> /// <param name="options"></param> public MapMiddleware(AppFunc next, MapOptions options) { if (next == null) { throw new ArgumentNullException("next"); } if (options == null) { throw new ArgumentNullException("options"); } if (options.PathMatch == null) { throw new ArgumentException(Resources.Exception_PathRequired); } _next = next; _options = options; }