加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 如何使用Response.OutputStream.Write将文件发送到浏

发布时间:2020-12-16 06:22:23 所属栏目:asp.Net 来源:网络整理
导读:我有一个页面用于从数据库中提取文件,并提示下载或流式传输到浏览器,具体取决于URL的格式.这工作正常,但是当我尝试设置页面标题时,我所做的任何事情都不起作用,它默认为URL中的域名. 我意识到这很有可能发生,因为我使用Response.OutputStream.Write(buffer,b
我有一个页面用于从数据库中提取文件,并提示下载或流式传输到浏览器,具体取决于URL的格式.这工作正常,但是当我尝试设置页面标题时,我所做的任何事情都不起作用,它默认为URL中的域名.

我意识到这很有可能发生,因为我使用Response.OutputStream.Write(buffer,bytesRead)向浏览器发送二进制文件,所以根据我在网上找到的其他东西“我用二进制文件填充缓冲区所以我无法控制标题“

You are filling up the buffer with a binary file,with no HTML and hence no Title Tag. I am not sure you have any control over the Title tag in the browser at this point. Let me check on a page I have up right now with a PDF. It does not look like this can be done,at least in the example I am looking at. I had another PDF opened,but it was to a local file directly and it had the Title tag set in the browser. I am not sure if this was embedded in the PDF or not.

在这里找到:http://forums.asp.net/t/1088814.aspx/1

我已经尝试了所有正常的地方来设置页面标题:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="FileServer.aspx.vb" Inherits="FileServer" Title="Title goes here" %>

要么

<head runat="server">
    <title>Title goes here</title>
</head>

要么

Protected Sub Page_Load(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Load
        Dim FileNumber As String = RouteData.Values("FileNumber")
        Dim Disposition As String = RouteData.Values("Disposition")

        If FileNumber IsNot Nothing Then
            Title = "Title goes here"
            ServeFile(FileNumber,Disposition)
        End If
End Sub

我有什么方法可以设置这个头衔还是我运气不好?

解决方法

在将文件发送到浏览器的同时,您无法设置标题.对于浏览器更改“页面”标题,它需要实际呈现HTML文档(即,它需要呈现页面).

在这种情况下,您不会发送任何有效的HTML内容,因此下载了您要发送的内容.

如果你想这样做,你需要做的就是做一些“反弹”.重定向到呈现标题的页面,以及您想要的任何其他内容(即aspx页面).从该页面“弹出”浏览器到下载.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读