private static IEnumerable <string> GetNamespaces(IMvcApplication mvcApplication)
        {
            if (mvcApplication.FileExists("~/Views/Web.config"))
            {
                var virtualContent = mvcApplication.GetVirtualContent("~/Views/Web.config");
                var doc            = new XmlDocument();
                using (var s = XmlReader.Create(virtualContent.Open()))
                {
                    doc.Load(s);

                    if (doc.DocumentElement != null)
                    {
                        var nodes = doc.DocumentElement
                                    .SelectNodes("/configuration/system.web.webPages.razor/pages/namespaces/add");
                        if (nodes != null)
                        {
                            foreach (XmlNode n in nodes)
                            {
                                if (n.Attributes != null)
                                {
                                    var ns = n.Attributes["namespace"].Value;
                                    if (!ns.Equals("System.Web.Mvc.Html") && !ns.Equals("System.Web.Optimization"))
                                    {
                                        yield return(ns);
                                    }
                                }
                            }
                        }
                    }
                }
                yield return("Xania.AspNet.Razor.Html");
            }
            else
            {
                var defaultList = new[]
                {
                    "System",
                    "System.Collections.Generic",
                    "System.Linq",
                    "System.Web.Mvc",
                    "System.Web.Mvc.Ajax",
                    "Xania.AspNet.Razor.Html",
                    "System.Web.Routing"
                };

                foreach (var ns in defaultList)
                {
                    yield return(ns);
                }
            }

            var auth = mvcApplication.Assemblies.Any(a => a.EndsWith("Microsoft.Web.WebPages.OAuth.dll"));

            if (auth)
            {
                yield return("DotNetOpenAuth.AspNet");

                yield return("Microsoft.Web.WebPages.OAuth");
            }
        }
예제 #2
0
        protected virtual string GetVirtualPath(ControllerContext controllerContext, string viewName)
        {
            var pathFormats = GetPathFormats(controllerContext.RouteData);

            foreach (var pathFormat in pathFormats)
            {
                var virtualPath = String.Format(pathFormat, viewName);

                if (_mvcApplication.FileExists(virtualPath))
                {
                    return(virtualPath);
                }
            }
            throw new HttpException(404, "View '" + viewName + "' not found");
        }
예제 #3
0
 public bool Exists(string virtualPath)
 {
     return(_mvcApplication.FileExists(virtualPath));
 }