bool ProcessDirectoryListingRequest() { if (_verb != "GET") { return(false); } String dirPathTranslated = _pathTranslated; if (_pathInfo.Length > 0) { // directory path can never have pathInfo dirPathTranslated = MapPath(_path); } if (!Directory.Exists(dirPathTranslated)) { return(false); } // get all files and subdirs FileSystemInfo[] infos = null; try { infos = (new DirectoryInfo(dirPathTranslated)).GetFileSystemInfos(); } catch { } // determine if parent is appropriate string parentPath = null; if (_path.Length > 1) { int i = _path.LastIndexOf('/', _path.Length - 2); parentPath = (i > 0) ? _path.Substring(0, i) : "/"; if (!_host.IsVirtualPathInApp(parentPath)) { parentPath = null; } } _connection.WriteEntireResponseFromString(200, "Content-type: text/html; charset=utf-8\r\n", Messages.FormatDirectoryListing(_path, parentPath, infos), false); return(true); }
bool ProcessDirectoryListingRequest() { if (_verb != "GET") { return(false); } String dirPathTranslated = _pathTranslated; if (_pathInfo.Length > 0) { // directory path can never have pathInfo dirPathTranslated = MapPath(_path); } if (!Directory.Exists(dirPathTranslated)) { return(false); } // have to redirect /foo to /foo/ to allow relative links to work if (!_path.EndsWith("/", StringComparison.Ordinal)) { string newPath = _path + "/"; string location = "Location: " + UrlEncodeRedirect(newPath) + "\r\n"; string body = "<html><head><title>Object moved</title></head><body>\r\n" + "<h2>Object moved to <a href='" + newPath + "'>here</a>.</h2>\r\n" + "</body></html>\r\n"; _connection.WriteEntireResponseFromString(302, location, body, false); return(true); } // check for the default file foreach (string filename in defaultFileNames) { string defaultFilePath = dirPathTranslated + "\\" + filename; if (File.Exists(defaultFilePath)) { // pretend the request is for the default file path _path += filename; _filePath = _path; _url = (_queryString != null) ? (_path + "?" + _queryString) : _path; _pathTranslated = defaultFilePath; return(false); // go through normal processing } } // get all files and subdirs FileSystemInfo[] infos = null; try { infos = (new DirectoryInfo(dirPathTranslated)).GetFileSystemInfos(); } catch { } // determine if parent is appropriate string parentPath = null; if (_path.Length > 1) { int i = _path.LastIndexOf('/', _path.Length - 2); parentPath = (i > 0) ? _path.Substring(0, i) : "/"; if (!_host.IsVirtualPathInApp(parentPath)) { parentPath = null; } } _connection.WriteEntireResponseFromString(200, "Content-type: text/html; charset=utf-8\r\n", Messages.FormatDirectoryListing(_path, parentPath, infos), false); return(true); }
private bool ProcessDirectoryListingRequest() { if (this._verb != "GET") { return(false); } int startIndex = this._pathTranslated.LastIndexOf('\\'); if (this._pathTranslated.IndexOf('.', startIndex) >= startIndex) { return(false); } if (!Directory.Exists(this._pathTranslated)) { return(false); } if (!this._path.EndsWith("/")) { string str = this._path + "/"; string extraHeaders = "Location: " + str + "\r\n"; string body = "<html><head><title>Object moved</title></head><body>\r\n<h2>Object moved to <a href='" + str + "'>here</a>.</h2>\r\n</body></html>\r\n"; this._conn.WriteEntireResponseFromString(0x12e, extraHeaders, body, false); return(true); } foreach (string str4 in s_defaultFilenames) { string str5 = this._pathTranslated + @"\" + str4; if (File.Exists(str5)) { this._path = this._path + str4; this._filePath = this._path; this._url = (this._queryString != null) ? (this._path + "?" + this._queryString) : this._path; this._pathTranslated = str5; return(false); } } FileSystemInfo[] elements = null; try { elements = new DirectoryInfo(this._pathTranslated).GetFileSystemInfos(); } catch { } string path = null; if (this._path.Length > 1) { int length = this._path.LastIndexOf('/', this._path.Length - 2); path = (length > 0) ? this._path.Substring(0, length) : "/"; if (!this._host.IsVirtualPathInApp(path)) { path = null; } } this._conn.WriteEntireResponseFromString(200, "Content-type: text/html; charset=utf-8\r\n", Messages.FormatDirectoryListing(this._path, path, elements), false); return(true); }