我有一个本地URL列表,我需要确定它们是否是"有效的MVC路径".如何检查URL(路径)是否映射到MVC控制器?
Phil Haack的Route Debugger将找到一条与当前请求匹配的路由,并使用当前的HttpContext进行匹配.我希望得到这些信息,而不是建立一个模拟HttpContext - 如果可能的话.
作为在Windows Azure上启动WebRole的一部分,我想访问正在启动的网站上的文件,我想在RoleEntryPoint.OnStart()中执行此操作.例如,这将使我能够在加载ASP.NET AppDomain之前影响ASP.NET配置.
当使用Azure SDK 1.3和VS2010在本地运行时,下面的示例代码可以解决这个问题,但是代码有很多黑客攻击,而且在部署到Azure时它不会起作用.
XNamespace srvDefNs = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition";
DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
string roleRoot = di.Parent.Parent.FullName;
XDocument roleModel = XDocument.Load(Path.Combine(roleRoot, "RoleModel.xml"));
var propertyElements = roleModel.Descendants(srvDefNs + "Property");
XElement sitePhysicalPathPropertyElement = propertyElements.Attributes("name").Where(nameAttr => nameAttr.Value == "SitePhysicalPath").Single().Parent;
string pathToWebsite = sitePhysicalPathPropertyElement.Attribute("value").Value;
Run Code Online (Sandbox Code Playgroud)
如何以在开发和Azure上工作的方式从RoleEntryPoint.OnStart()获取WebRole站点根路径?