/// <devdoc> /// Gets the appropriate mapped path for the DataFile. /// </devdoc> private string GetPhysicalDataFilePath() { string filename = DataFile; if (filename.Length == 0) { return(null); } if (!System.Web.Util.UrlPath.IsAbsolutePhysicalPath(filename)) { // Root relative path if (DesignMode) { // This exception should never be thrown - the designer always maps paths // before using the runtime control. throw new NotSupportedException(SR.GetString(SR.AccessDataSource_DesignTimeRelativePathsNotSupported, ID)); } filename = Context.Request.MapPath(filename, AppRelativeTemplateSourceDirectory, true); } HttpRuntime.CheckFilePermission(filename, true); // We also need to check for path discovery permissions for the // file since the page developer will be able to see the physical // path in the ConnectionString property. if (!HttpRuntime.HasPathDiscoveryPermission(filename)) { throw new HttpException(SR.GetString(SR.AccessDataSource_NoPathDiscoveryPermission, HttpRuntime.GetSafePath(filename), ID)); } return(filename); }
/// <devdoc> /// Gets the ad data for the given file by loading the file, or reading from the /// application-level cache. /// </devdoc> private AdRec [] GetFileData(string fileName) { // VSWhidbey 208626: Adopting similar code from xml.cs to support virtual path provider // First, figure out if it's a physical or virtual path VirtualPath virtualPath; string physicalPath; ResolvePhysicalOrVirtualPath(fileName, out virtualPath, out physicalPath); // try to get it from the ASP.NET cache string fileKey = CacheInternal.PrefixAdRotator + ((!String.IsNullOrEmpty(physicalPath)) ? physicalPath : virtualPath.VirtualPathString); CacheStoreProvider cacheInternal = System.Web.HttpRuntime.Cache.InternalCache; AdRec[] adRecs = cacheInternal.Get(fileKey) as AdRec[]; if (adRecs == null) { // Otherwise load it CacheDependency dependency; try { using (Stream stream = OpenFileAndGetDependency(virtualPath, physicalPath, out dependency)) { adRecs = LoadStream(stream); Debug.Assert(adRecs != null); } } catch (Exception e) { if (!String.IsNullOrEmpty(physicalPath) && HttpRuntime.HasPathDiscoveryPermission(physicalPath)) { // We want to catch the error message, but not propage the inner exception. Otherwise we can throw up // logon prompts through IE; throw new HttpException(SR.GetString(SR.AdRotator_cant_open_file, ID, e.Message)); } else { throw new HttpException(SR.GetString(SR.AdRotator_cant_open_file_no_permission, ID)); } } // Cache it, but only if we got a dependency if (dependency != null) { using (dependency) { // and store it in the cache, dependent on the file name cacheInternal.Insert(fileKey, adRecs, new CacheInsertOptions() { Dependencies = dependency }); } } } return(adRecs); }
private AdRec[] GetFileData(string fileName) { VirtualPath path; string str; base.ResolvePhysicalOrVirtualPath(fileName, out path, out str); string key = "n" + (!string.IsNullOrEmpty(str) ? str : path.VirtualPathString); CacheInternal cacheInternal = HttpRuntime.CacheInternal; AdRec[] recArray = cacheInternal[key] as AdRec[]; if (recArray == null) { CacheDependency dependency; try { using (Stream stream = base.OpenFileAndGetDependency(path, str, out dependency)) { recArray = this.LoadStream(stream); } } catch (Exception exception) { if (!string.IsNullOrEmpty(str) && HttpRuntime.HasPathDiscoveryPermission(str)) { throw new HttpException(System.Web.SR.GetString("AdRotator_cant_open_file", new object[] { this.ID, exception.Message })); } throw new HttpException(System.Web.SR.GetString("AdRotator_cant_open_file_no_permission", new object[] { this.ID })); } if (dependency == null) { return(recArray); } using (dependency) { cacheInternal.UtcInsert(key, recArray, dependency); } } return(recArray); }
private string GetPhysicalDataFilePath() { string dataFile = this.DataFile; if (dataFile.Length == 0) { return(null); } if (!UrlPath.IsAbsolutePhysicalPath(dataFile)) { if (base.DesignMode) { throw new NotSupportedException(System.Web.SR.GetString("AccessDataSource_DesignTimeRelativePathsNotSupported", new object[] { this.ID })); } dataFile = this.Context.Request.MapPath(dataFile, base.AppRelativeTemplateSourceDirectory, true); } HttpRuntime.CheckFilePermission(dataFile, true); if (!HttpRuntime.HasPathDiscoveryPermission(dataFile)) { throw new HttpException(System.Web.SR.GetString("AccessDataSource_NoPathDiscoveryPermission", new object[] { HttpRuntime.GetSafePath(dataFile), this.ID })); } return(dataFile); }