//----------------------------------------------------------------------- // // Copyright (C) 2011 Microsoft Corporation // //----------------------------------------------------------------------- namespace Microsoft.Samples.Management.OData.RoleBasedPlugins { using System.IO; using System.Web; /// /// Helper class with some utility functions /// internal static class Utils { /// /// Get base path /// /// Gets the base path to find the RBAC configuration file public static string GetBasePath() { string path = null; if (HttpContext.Current != null) { path = HttpContext.Current.Server.MapPath("."); } else { path = Directory.GetCurrentDirectory(); } string basePath = System.Configuration.ConfigurationManager.AppSettings["BasePath"]; if (string.IsNullOrEmpty(basePath) == false) { return Path.Combine(path, basePath); } else { return path; } } /// /// Gets RBAC configuration path /// /// Rbac configuratio file path public static string GetRbacFilePath() { string rbacFileName = System.Configuration.ConfigurationManager.AppSettings["RbacFileName"]; if (string.IsNullOrEmpty(rbacFileName)) { rbacFileName = "RbacConfiguration.xml"; } string basePath = System.Configuration.ConfigurationManager.AppSettings["BasePath"]; if (string.IsNullOrEmpty(basePath) == false) { rbacFileName = Path.Combine(basePath, rbacFileName); } string path = null; if (HttpContext.Current != null) { path = HttpContext.Current.Server.MapPath("."); } else { path = Directory.GetCurrentDirectory(); } return Path.Combine(path, rbacFileName); } } }