Beispiel #1
0
        static UrlBaseMapHandler ConfigureFileHandler(JObject config)
        {
            if (config != null)
            {
                JObject hand = config["simpleFileHandler"] as JObject; //allows us to host static files
                if (hand != null)
                {
                    JArray urls;
                    JValue root = hand["rootDirectory"] as JValue;
                    if (root != null)
                    {
                        string rootDir = root.ToString();
                        if (!string.IsNullOrEmpty(rootDir))
                        {
                            urls = hand["defaultFiles"] as JArray;
                            if (urls != null)
                            {
                                List <string> defFiles = new List <string>();
                                foreach (JToken cur in urls)
                                {
                                    string tmp = cur.ToString();
                                    if (!string.IsNullOrEmpty(tmp))
                                    {
                                        defFiles.Add(tmp);
                                    }
                                }
                                if (defFiles.Count > 0)
                                {
                                    urls = hand["allowedExtensions"] as JArray;
                                    if (urls != null)
                                    {
                                        FileExtensions exts = new FileExtensions();
                                        foreach (JToken cur in urls)
                                        {
                                            string tmp = cur.ToString();
                                            if (!string.IsNullOrEmpty(tmp))
                                            {
                                                exts.Add(tmp);
                                            }
                                        }

                                        if (exts.Count > 0)
                                        {
                                            SimpleFileHandler handler = new SimpleFileHandler(rootDir, defFiles, MimeTypes.GetAllWellKnown(), exts, new FileExtensions()); //so we can also have static files
                                            return(new UrlBaseMapHandler(handler, new string[] { "/" }));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
 public SimpleFileHandler(string localPath, string defaultFile) : this(localPath, new string[] { defaultFile }, MimeTypes.GetAllWellKnown(), null, null)
 {
 }
Beispiel #3
0
        private static IHandlerMapper InitFiles(ConfigurationProviderBase prov)
        {
            ConfigurationParameter param = prov.Get(typeof(SimpleFileHandler), "rootDirectory");

            if (param != null)
            {
                string rootDir = (string)param.Value;

                param = prov.Get(typeof(SimpleFileHandler), "logicalDirectory");
                if (param != null)
                {
                    string localDir = (string)param.Value;

                    string[] defFiles;
                    param = prov.Get(typeof(SimpleFileHandler), "defaultFiles");
                    if (param != null)
                    {
                        defFiles = (string[])param.Value;

                        FileExtensions exts = new FileExtensions();
                        param = prov.Get(typeof(SimpleFileHandler), "allowedExtensions");
                        if (param != null)
                        {
                            string[] tmp = (string[])param.Value;
                            foreach (string cur in tmp)
                            {
                                exts.Add(cur);
                            }
                            SimpleFileHandler handler = new SimpleFileHandler(rootDir, defFiles, MimeTypes.GetAllWellKnown(), exts, new FileExtensions());                             //so we can also have static files
                            return(new UrlBaseMapHandler(handler, new string[] { localDir }));
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #4
0
 public SimpleFileHandler(string localPath) : this(localPath, null, MimeTypes.GetAllWellKnown(), null, null)
 {
 }