internal static string GetSafePath(string linePragma) { string virtualPathFromHttpLinePragma = GetVirtualPathFromHttpLinePragma(linePragma); if (virtualPathFromHttpLinePragma != null) { return(virtualPathFromHttpLinePragma); } return(HttpRuntime.GetSafePath(linePragma)); }
private string GetDisplayPath() { if (this.VirtualPath != null) { return(this.VirtualPath); } if (this.PhysicalPath != null) { return(HttpRuntime.GetSafePath(this.PhysicalPath)); } return(null); }
internal static HttpException CreateFileMonitoringException(int hr, string path) { string str; bool flag = false; switch (hr) { case -2147024894: case -2147024893: str = "Directory_does_not_exist_for_monitoring"; break; case -2147024891: str = "Access_denied_for_monitoring"; flag = true; break; case -2147024840: str = "NetBios_command_limit_reached"; flag = true; break; case -2147024809: str = "Invalid_file_name_for_monitoring"; break; default: str = "Failed_to_start_monitoring"; break; } if (flag) { System.Web.UnsafeNativeMethods.RaiseFileMonitoringEventlogEvent(System.Web.SR.GetString(str, new object[] { HttpRuntime.GetSafePath(path) }) + "\n\r" + System.Web.SR.GetString("App_Virtual_Path", new object[] { HttpRuntime.AppDomainAppVirtualPath }), path, HttpRuntime.AppDomainAppVirtualPath, hr); } return(new HttpException(System.Web.SR.GetString(str, new object[] { HttpRuntime.GetSafePath(path) }), hr)); }
internal /*public*/ string GetHtmlErrorMessage(bool dontShowSensitiveInfo) { // Give the formatter a chance to prepare its state PrepareFormatter(); StringBuilder sb = new StringBuilder(); // REVIEW: all the derived method should work directly with the string // builder instead of returning a string. sb.Append("<html>\r\n"); sb.Append(" <head>\r\n"); sb.Append(" <title>" + ErrorTitle + "</title>\r\n"); sb.Append(" <style>\r\n"); sb.Append(" body {font-family:\"Verdana\";font-weight:normal;font-size: .7em;color:black;} \r\n"); sb.Append(" p {font-family:\"Verdana\";font-weight:normal;color:black;margin-top: -5px}\r\n"); sb.Append(" b {font-family:\"Verdana\";font-weight:bold;color:black;margin-top: -5px}\r\n"); sb.Append(" H1 { font-family:\"Verdana\";font-weight:normal;font-size:18pt;color:red }\r\n"); sb.Append(" H2 { font-family:\"Verdana\";font-weight:normal;font-size:14pt;color:maroon }\r\n"); sb.Append(" pre {font-family:\"Lucida Console\";font-size: .9em}\r\n"); sb.Append(" .marker {font-weight: bold; color: black;text-decoration: none;}\r\n"); sb.Append(" .version {color: gray;}\r\n"); sb.Append(" .error {margin-bottom: 10px;}\r\n"); sb.Append(" .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }\r\n"); sb.Append(" </style>\r\n"); sb.Append(" </head>\r\n\r\n"); sb.Append(" <body bgcolor=\"white\">\r\n\r\n"); sb.Append(" <span><H1>" + HttpRuntime.FormatResourceString(SR.Error_Formatter_ASPNET_Error, HttpRuntime.AppDomainAppVirtualPath) + "<hr width=100% size=1 color=silver></H1>\r\n\r\n"); sb.Append(" <h2> <i>" + ErrorTitle + "</i> </h2></span>\r\n\r\n"); sb.Append(" <font face=\"Arial, Helvetica, Geneva, SunSans-Regular, sans-serif \">\r\n\r\n"); sb.Append(" <b> " + HttpRuntime.FormatResourceString(SR.Error_Formatter_Description) + " </b>" + Description + "\r\n"); sb.Append(" <br><br>\r\n\r\n"); if (MiscSectionTitle != null) { sb.Append(" <b> " + MiscSectionTitle + ": </b>" + MiscSectionContent + "<br><br>\r\n\r\n"); } WriteColoredSquare(sb, ColoredSquareTitle, ColoredSquareDescription, ColoredSquareContent, WrapColoredSquareContentLines); if (ShowSourceFileInfo) { string fileName = HttpRuntime.GetSafePath(SourceFileName); if (fileName == null) { fileName = HttpRuntime.FormatResourceString(SR.Error_Formatter_No_Source_File); } sb.Append(" <b> " + HttpRuntime.FormatResourceString(SR.Error_Formatter_Source_File) + " </b> " + fileName + "<b> " + HttpRuntime.FormatResourceString(SR.Error_Formatter_Line) + " </b> " + SourceFileLineNumber + "\r\n"); sb.Append(" <br><br>\r\n\r\n"); } // If it's a FileNotFoundException/FileLoadException/BadImageFormatException with a FusionLog, // write it out (ASURT 83587) if (!dontShowSensitiveInfo && Exception != null) { // (Only display the fusion log in medium or higher (ASURT 126827) if (HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Medium)) { for (Exception e = Exception; e != null; e = e.InnerException) { string fusionLog = null; string filename = null; FileNotFoundException fnfException = e as FileNotFoundException; if (fnfException != null) { fusionLog = fnfException.FusionLog; filename = fnfException.FileName; } FileLoadException flException = e as FileLoadException; if (flException != null) { fusionLog = flException.FusionLog; filename = flException.FileName; } BadImageFormatException bifException = e as BadImageFormatException; if (bifException != null) { fusionLog = bifException.FusionLog; filename = bifException.FileName; } if (fusionLog != null && fusionLog.Length > 0) { WriteColoredSquare(sb, HttpRuntime.FormatResourceString(SR.Error_Formatter_FusionLog), HttpRuntime.FormatResourceString(SR.Error_Formatter_FusionLogDesc, filename), HttpUtility.HtmlEncode(fusionLog), false /*WrapColoredSquareContentLines*/); break; } } } } WriteColoredSquare(sb, ColoredSquare2Title, ColoredSquare2Description, ColoredSquare2Content, false); if (!dontShowSensitiveInfo) // don't show version for security reasons { sb.Append(" <hr width=100% size=1 color=silver>\r\n\r\n"); sb.Append(" <b>" + HttpRuntime.FormatResourceString(SR.Error_Formatter_Version) + "</b> " + HttpRuntime.FormatResourceString(SR.Error_Formatter_CLR_Build) + VersionInfo.ClrVersion + HttpRuntime.FormatResourceString(SR.Error_Formatter_ASPNET_Build) + VersionInfo.IsapiVersion + "\r\n\r\n"); sb.Append(" </font>\r\n\r\n"); } sb.Append(" </body>\r\n"); sb.Append("</html>\r\n"); sb.Append(PostMessage); return(sb.ToString()); }
internal void StopMonitoringPath(string alias, object target) { if (!this.IsFCNDisabled) { DirectoryMonitor directoryMonitor = null; string fileNameLong = null; if (alias == null) { throw new HttpException(System.Web.SR.GetString("Invalid_file_name_for_monitoring", new object[] { string.Empty })); } using (new ApplicationImpersonationContext()) { this._lockDispose.AcquireReaderLock(); try { if (!this._disposed) { FileMonitor monitor = (FileMonitor)this._aliases[alias]; if (monitor != null) { directoryMonitor = monitor.DirectoryMonitor; fileNameLong = monitor.FileNameLong; } else { if ((alias.Length == 0) || !UrlPath.IsAbsolutePhysicalPath(alias)) { throw new HttpException(System.Web.SR.GetString("Invalid_file_name_for_monitoring", new object[] { HttpRuntime.GetSafePath(alias) })); } string fullPath = GetFullPath(alias); directoryMonitor = this.FindDirectoryMonitor(fullPath, false, false); if (directoryMonitor == null) { string directoryOrRootName = UrlPath.GetDirectoryOrRootName(fullPath); fileNameLong = Path.GetFileName(fullPath); if (!string.IsNullOrEmpty(fileNameLong)) { directoryMonitor = this.FindDirectoryMonitor(directoryOrRootName, false, false); } } } if (directoryMonitor != null) { directoryMonitor.StopMonitoringFile(fileNameLong, target); } } } finally { this._lockDispose.ReleaseReaderLock(); } } } }
internal DateTime StartMonitoringPath(string alias, FileChangeEventHandler callback, out FileAttributesData fad) { FileMonitor monitor = null; DirectoryMonitor monitor2 = null; string fullPath; string file = null; bool flag = false; fad = null; if (alias == null) { throw new HttpException(System.Web.SR.GetString("Invalid_file_name_for_monitoring", new object[] { string.Empty })); } if (this.IsFCNDisabled) { fullPath = GetFullPath(alias); FindFileData data = null; if (FindFileData.FindFile(fullPath, out data) == 0) { fad = data.FileAttributesData; return(data.FileAttributesData.UtcLastWriteTime); } return(DateTime.MinValue); } using (new ApplicationImpersonationContext()) { this._lockDispose.AcquireReaderLock(); try { if (this._disposed) { return(DateTime.MinValue); } monitor = (FileMonitor)this._aliases[alias]; if (monitor != null) { file = monitor.FileNameLong; monitor = monitor.DirectoryMonitor.StartMonitoringFileWithAssert(file, callback, alias); } else { flag = true; if ((alias.Length == 0) || !UrlPath.IsAbsolutePhysicalPath(alias)) { throw new HttpException(System.Web.SR.GetString("Invalid_file_name_for_monitoring", new object[] { HttpRuntime.GetSafePath(alias) })); } fullPath = GetFullPath(alias); if (this.IsBeneathAppPathInternal(fullPath)) { monitor2 = this._dirMonAppPathInternal; file = fullPath.Substring(this._appPathInternal.Length + 1); monitor = monitor2.StartMonitoringFileWithAssert(file, callback, alias); } else { monitor2 = this.FindDirectoryMonitor(fullPath, false, false); if (monitor2 != null) { monitor = monitor2.StartMonitoringFileWithAssert(null, callback, alias); } else { string directoryOrRootName = UrlPath.GetDirectoryOrRootName(fullPath); file = Path.GetFileName(fullPath); if (!string.IsNullOrEmpty(file)) { monitor2 = this.FindDirectoryMonitor(directoryOrRootName, false, false); if (monitor2 != null) { try { monitor = monitor2.StartMonitoringFileWithAssert(file, callback, alias); } catch { } if (monitor != null) { goto Label_01C7; } } } monitor2 = this.FindDirectoryMonitor(fullPath, true, false); if (monitor2 != null) { file = null; } else { if (string.IsNullOrEmpty(file)) { throw CreateFileMonitoringException(-2147024809, alias); } monitor2 = this.FindDirectoryMonitor(directoryOrRootName, true, true); } monitor = monitor2.StartMonitoringFileWithAssert(file, callback, alias); } } } Label_01C7: if (!monitor.IsDirectory) { monitor.DirectoryMonitor.GetFileAttributes(file, out fad); } if (flag) { this._aliases[alias] = monitor; } } finally { this._lockDispose.ReleaseReaderLock(); } if (fad != null) { return(fad.UtcLastWriteTime); } return(DateTime.MinValue); } }