Response.Redirect的到从UI.Page继承类? [英] Response.Redirect to Class that inherits from UI.Page?

查看:158
本文介绍了Response.Redirect的到从UI.Page继承类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,感谢您的时间。

everyone, thank for your time.

嗯,这我的问题(当然这不是一个probleam的话),可能有从ui.page继承,然后实例类的一个对象类,做一个重定向呢?

Well this my problem (well it's not a probleam at all), it is possible to have a class that inherits from ui.page and then instance an object of that class and do a redirect to it ?

事情是这样的:

Public sub myMethod() 
    Dim myPage as new myClassThatInheritsFromUIPage()
    Response.redirect(myPage) 'Here is one of my "no-idea" line
end sub

我在WebForm中做到这一点(和我想要的,从ui.page继承的类做):

I do this in my webForm (and that what I want to do in a class that inherits from ui.page):

Response.BufferOutput = True  
Response.ClearContent()
Response.ClearHeaders()
ostream=crReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
Response.AppendHeader("Cache-Control", "force-download")
Response.AppendHeader("Content-disposition","attachment;filename=ReportAsPDF.pdf")
Response.ContentType = "application/pdf"
Response.BinaryWrite(ostream.ToArray())
Response.Flush()  
HttpContext.Current.ApplicationInstance.CompleteRequest()

我想要做的是与正常的WebForm完全可能的,但我的web窗体不会呈现什么都没有(至少为(X)HTML的话,那是因为我想知道如果有什么我问的是能够实现

What I want to do is perfectly possible with a normal WebForm, but my webForm doesn't render nothing at all (at least as (x)html so, that's because I would like to know if what I'm asking is possible to achieve.

感谢大家。

嗯,最后我只是添加HttpContext.Current。以所有包含一个响应属性行,所以我现在只是一个类,不是从UI.Page继承而只是调用清除缓冲区(自定义方法)的方法中,添加标题(强制下载,设置MIME类型和文件名),并刷新自身的反应和得到的效果/使用我想它。

Well at the end I just add "HttpContext.Current." to all the lines that include a "response" attribute, so now I have just a class that NOT inherits from "UI.Page" and just call the method that clear the buffer (a custom method), add the headers (to force the download,set the mime type and filename) and flush the response by itself and get the effect/use I want it.

为了访问会话增值经销商,只需加上HttpContext.Current。和它的作品,我不知道如何安全,或者是一个好办法,但似乎效果不佳。

In order to access to the Session vars just add "HttpContext.Current." and it works, I don't know how secure or if is a good way,but appears to work well.

所以,code现在看起来是这样的:

So the code now looks something like this:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.ReportSource

Namespace foo
  Public Class requestReport


    'just to instance the object'
    Public Sub New()


    End Sub


    Public Sub downloadReport()
     'do all the stuff to connect and load the report'
         HttpContext.Current.Response.BufferOutput = True  
         HttpContext.Current.Response.ClearContent()
         HttpContext.Current.Response.ClearHeaders()
  ostream=crReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
        HttpContext.Current.Response.AppendHeader("Cache-Control", "force-download")
        HttpContext.Current.Response.AppendHeader("Content-disposition","attachment;filename=ReportAsPDF.pdf")
        HttpContext.Current.Response.ContentType = "application/pdf"
        HttpContext.Current.Response.BinaryWrite(ostream.ToArray())
        HttpContext.Current.Response.Flush()  
        HttpContext.Current.ApplicationInstance.CompleteRequest()
     End Sub
   End Class 
 End Namespace

和从命令为例做到这一点:

And from a command for example do this:

dim myReport as new foo.requestReport()
myReport.downloadReport() 

当然,现在你可以,如果你需要添加更多的属性或方法。

Of course now you can add more attributes or method if you need it.

所以,现在我甚至不不要中使用Response.Redirect(),或从UI.Page,只是一个类继承了变革的当前响应和刷新在与水晶报表动态创建的内容,我觉得我是那种完全丧失,但你的答案真的帮助我,特别是什么 TEJS 说,什么是基本相同或相同的什么,我只是做了。谢谢你。

So now I don't even don't use Response.redirect() or inherits from "UI.Page", just a class that "change" the "current response" and "flush" the content created on fly with the crystal report, I think I was kind of totally lost but your answers really help me, especially what Tejs says, what is almost the same or the same what I just did. Thank you.

更新:
顺便说一句,我刚刚意识到的ReportDocument类有这个方法: ExportToHtt presponse ,让我们刷新水晶报表浏览器为PDF / XSL等强制(或没有)的下载该文件。

UPDATE: By the way, I just realize that the ReportDocument class has this method: ExportToHttpResponse that let us flush the Crystal Report to the browser as PDF/XSL etc forcing (or not) the download of the file.

推荐答案

尝试只是在做这个:

HttpContext.Current.Response.Redirect("...");

这篇关于Response.Redirect的到从UI.Page继承类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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