コード例 #1
0
        //Routing
        public void AddFile(string url, string path)
        {
            FileInfo i = new FileInfo(path);

            if (!i.Exists)
            {
                throw new FileNotFoundException($"File '{path}' not found");
            }

            if (i.Extension.ToLower() == ".cshtml")
            {
                try
                {
                    RazorCache.AddTemplate(i.Name, File.ReadAllText(i.FullName));
                }
                catch (Exception ex)
                {
                    if (OnException != null)
                    {
                        OnException("AddFile", ex);
                    }
                    if (Debug)
                    {
                        RazorCache.AddTemplate(i.Name, $"Exception found in Razor Template:\n {ex.Message.Replace("@", "@@")}");
                    }
                    else
                    {
                        RazorCache.AddTemplate(i.Name, $"Exception found in Razor Template, enable debug to see exception");
                    }
                }
            }
            Routing.AddFileRoute(url, i.FullName);
        }