Esempio n. 1
0
 public DeepLinkingStrictMiddleware(RequestDelegate next,
                                    IHostingEnvironment hostingEnv,
                                    ILoggerFactory loggerFactory,
                                    DeepLinkingStrictMiddlewareOptions strictOptions)
     : base(next, hostingEnv, loggerFactory, strictOptions)
 {
     this.strictOptions = strictOptions;
 }
Esempio n. 2
0
        public static IApplicationBuilder UseDeepLinking(this IApplicationBuilder app, DeepLinkingOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app), "Passed application builder cannot be null");
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options), "Passed options cannot be null");
            }

            string absolutePhysicalRootPath = Path.Combine(options.BaseFileSystemPath, options.LocalFilesRelativePath);

            var redirectUrlPath = new PathString(options.ClientRedirectPath);

            var allowedClientPaths = options.AllowedClientPaths ?? new string[0];

            bool usingStrict = allowedClientPaths.Any();

            var ignoredClientPaths = options.IgnoredClientPaths ?? new string[0];

            PathString[] ignoredPathStrings = ignoredClientPaths
                                              .Select(url => new PathString(url)).ToArray();

            Func <IApplicationBuilder> useMiddleware;

            if (!usingStrict)
            {
                var middlewareOptions = new DeepLinkingMiddlewareOptions()
                {
                    AbsolutePhysicalRootPath = absolutePhysicalRootPath,
                    RedirectUrlPath          = redirectUrlPath,
                    IgnoredRoutePaths        = ignoredPathStrings,
                };

                useMiddleware = () => app.UseMiddleware <DeepLinkingMiddleware>(middlewareOptions);
            }
            else
            {
                PathString[] allowedPathStrings = allowedClientPaths
                                                  .Select(url => new PathString(url)).ToArray();

                var strictMiddlewareOptions = new DeepLinkingStrictMiddlewareOptions()
                {
                    AbsolutePhysicalRootPath = absolutePhysicalRootPath,
                    RedirectUrlPath          = redirectUrlPath,
                    AllowedRoutePaths        = allowedPathStrings,
                    IgnoredRoutePaths        = ignoredPathStrings,
                };

                useMiddleware = () => app.UseMiddleware <DeepLinkingStrictMiddleware>(strictMiddlewareOptions);
            }

            return(useMiddleware());
        }