Change uncertainty to confirmation ~ The Uri text file is downloaded to a local file instead of being automatically opened by the browser.
Back to directory
This title is a bit long. In short, it indicates whether a user can be prompted for saving a file, rather than opening it in a browser, there is a fatal problem in opening a browser, that is, if your page encoding is inconsistent with the file encoding, garbled code will be opened. In fact, this article mainly solves this problem.
The above URI format file opened directly using the browser, because the file encoding is GB2312 and web code is a UTF-8, so the text on the page becomes garbled.
After knowing the root cause of the problem, we can solve it again. First, we cannot control the file encoding on the URI. Therefore, we can only read it locally (WWW server ), then perform secondary organization and return it to the client (your browser). For a URI file, we cannot directly return it. We must read it as a stream before returning it. In fact ,. net is a simple encapsulation for us. The following is the implementation code. Let's take a look:
/// <Summary> /// download the object, synchronization supports local and URI files /// </summary> /// <param name = "path"> </param> /// <returns> </returns> public actionResult DownLoad (string path) {if (path. indexOf ("http: //") <0) {string localPath = Server. mapPath ("/" + path); string contentType = MimeMapping. getMimeMapping (localPath); return File (localPath, contentType, "download File");} else {var url = new Uri (path); HttpWebRequest request = (HttpWebRequest) System. net. webRequest. create (path); HttpWebResponse response = (HttpWebResponse) request. getResponse (); Stream stream = response. getResponseStream (); var contentType = response. contentType; // get the total File size. return File (stream, contentType, "download File ");}}
Download video:
Back to directory
How can I automatically convert a TXT file into html format when it is opened in a browser?
For struts, use <c: out value = "$ {XXX}" escapeXml = "false"/>
For example, in the JS, use the keyword ("#id”).html (value );
In the es file browser, I created a new text file in it. It seems that the default file is accidentally selected and cannot be opened now.
Elasticsearch does not display the webpage option when opening text.
Clear the cache. If it still does not work, delete and reinstall it.