写流在ASP.Net响应 [英] Writing a stream to the response in ASP.Net

查看:140
本文介绍了写流在ASP.Net响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧只是想澄清我的解决方案的东西。

Ok just want to clarify something with my solution.

我有一个要求,抓住从程序存储库某处一个文件,这个仓库需要与文件的要求沿cookie的形式传递会话令牌。

I have a requirement to grab a file from a respository somewhere, this repository requires a session token to be passed in the form of a cookie along with the request for the file.

我进行身份验证这个库的用户和存储用户的Cookie集合在会话令牌我的应用程序,当用户第一次登录到我的应用程序。

I am authenticating the user against this repository and storing the session token in the users cookie collection for my application when the user first logs onto my application.

问题是,当用户试图访问一个文件,因为存储库是在不同的URL和域名cookie将不会被发送到存储库。因此我创建一个新的HTTP请求,追加cookie,并得到响应流回来。

Problem is the cookie will not get sent to the repository when a user tried to access a file because the repository is on a different URL and domain. Therefore I am creating a new http request, appending the cookie and getting the response stream back.

我现在需要此响应流发送回用户,标头和所有(如本响应流将包含用户试图访问该文件的标头)

I now need to send this response stream back to the user, headers and all (as this response stream will contain the headers for the file the user is trying to access)

我可以使用这样的:

            string session = cookie.Value;
            StreamReader reader = new StreamReader(Utility.GetLinkStream(url, session));
            Context.Response.ClearHeaders();
            Context.Response.Clear();
            Context.Response.Write(reader.ReadToEnd());

实质上调用Utility.GetLinkStream熄灭,并创建一个HTTP请求,然后返回响应的流。会写调用写出来的整个响应头和所有,或是否有更好的方式来达致这?

Essentially the call to Utility.GetLinkStream goes off and creates a http request then returns the stream of the response. Will the call to Write write out the whole response headers and all, or is there a better way to acheive this?

推荐答案

的Response.Write()将只写内容,你必须调用此之前设置的头。你可以从WebResponse的枚举头并将其添加到手动Response.Headers。

Response.Write() will only write content, you have to set the headers before calling this. You could enumerate the headers from the WebResponse and add them to the Response.Headers manually.

这篇关于写流在ASP.Net响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆