Response.Redirect 到继承自 UI.Page 的类?

发布于 2024-11-30 23:57:04 字数 2745 浏览 1 评论 0原文

各位,谢谢您的宝贵时间。

好吧,这是我的问题(好吧,这根本不是问题),是否可以有一个继承自 ui.page 的类,然后实例化该类的对象并重定向到它?

像这样的事情:

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

我在我的 webForm 中执行此操作(并且我想在继承自 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 来说是完全可能的,但我的 webForm 不渲染任何内容完全(至少作为(x)html所以,那是因为我想知道我所要求的是否可以实现。

谢谢大家。

最后我只是添加“HttpContext.Current”。 到所有行包括“响应”属性,所以现在我只有一个不继承自“UI.Page”的类,只需调用清除缓冲区的方法(自定义方法),添加标头(强制下载,设置mime 类型和文件名)并自行刷新响应并获得我想要的效果/使用

为了访问会话变量,只需添加“HttpContext.Current”即可。是一个好方法,但是看起来效果很好,

所以代码现在看起来像这样:

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

例如,从命令执行此操作:

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

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

所以现在我什至不使用 Response.redirect() 或继承“UI.Page”,只是一个“更改”“当前响应”和“刷新”内容的类使用水晶报告即时创建,我想我完全迷失了,但你的回答确实对我有帮助,特别是 Tejs 所说的,与我刚刚所做的几乎相同或相同的内容。谢谢。

更新: 顺便说一句,我刚刚意识到 ReportDocument 类有这个方法:ExportToHttpResponse,它让我们将水晶报表以 PDF/XSL 等方式刷新到浏览器,强制(或不)下载文件。

everyone, thank for your time.

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 ?

Something like this:

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

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()

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.

Thank you everyone.

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.

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.

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.

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

在巴黎塔顶看东京樱花 2024-12-07 23:57:04

否,因为当前没有接受 UI.Page 实例的重载。但是,您可以在新页面上调用 Render 方法并直接写入响应流。又称

  1. 清除响应缓冲区。
  2. 将页面实例渲染到响应缓冲区。
  3. 调用 Response.End() 刷新请求并将其发送到客户端。

如果您的新页面实际上没有执行任何操作,您还可以不随响应发回任何内容。

No, as there is no current overload that accepts a UI.Page instance. However, you could call the Render method on your new page and write directly to the response stream. AKA

  1. Clear the Response Buffer.
  2. Render your page instance to the response buffer.
  3. Invoke Response.End() to flush the request and send it to the client.

If your new page doesnt actually do anything, you can additional just send no content back with the response.

倥絔 2024-12-07 23:57:04

您可以使用 Server.Transfer 并传入要传输到的页面对象的实例。

这是文档:HttpServerUtility.Transfer

You can use Server.Transfer and pass in the instance of the page object that you want to tranfer to.

Here is the documentation: HttpServerUtility.Transfer

已下线请稍等 2024-12-07 23:57:04

尝试这样做:

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

Try just doing this instead:

HttpContext.Current.Response.Redirect("...");
不疑不惑不回忆 2024-12-07 23:57:04
 HttpRequest Request = HttpContext.Current.Request;
 HttpResponse Response = HttpContext.Current.Response; 

之后您可以重定向任何页面。

 HttpRequest Request = HttpContext.Current.Request;
 HttpResponse Response = HttpContext.Current.Response; 

And after that you can redirect any page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文