ASP。网络无负载页面

时间:2011-07-19 19:22:14

标签: asp.net

以下回复将我的Windows应用程序发送到我的网站 http://www.abcd.com/response.aspx?name=bala

响应页面我不想加载。

在哪个事件中我编写代码来获取像'name'这样的参数

页面加载

dim str as string=request.querystring('name')

我得到了名字。但我不想加载该页面。 我希望存储任何文本文件的所有响应。可以在asp.net中加载页面吗?

4 个答案:

答案 0 :(得分:1)

您可以更改页面的内容类型,使其不会尝试在浏览器中加载,而是为您打开文本文件。像这样:

这是.aspx页面:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="myPage_export.aspx.vb" Inherits="myPage_export" %>

以下是代码隐藏:

Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data
Imports System.Web.Configuration

Partial Class myPage_export
    Inherits system.web.ui.page

       Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

       dim str as string=request.querystring('name')
       If str = "whatever" THEN 'send text file instead
          mytxt = 'Open or Create your text file here

           myFileName = "testfile.txt"

           Response.ContentType = "application/txt" '<--verify the txt part -- I'm not sure if that's the correct code

           Response.AddHeader("Content-Disposition", "attachment;filename=" + myFileName)

           Response.Write(mytxt)
        Else 'let them open a web page
           response.redirect("some web page")
        End
    End Sub

End Class

答案 1 :(得分:0)

如果您不想加载页面,可以执行Response.Redirect到另一个页面。使用Page_Init在Load事件之上的某个级别处理此问题。

答案 2 :(得分:0)

如果您不想向客户发送任何回复,您只需发送204无响应http标头即可。我认为page_load中的单行代码就足够了。

Response.StatusCode = 204

答案 3 :(得分:0)

在ASP.NET中使用WebForms,您将返回一些描述的页面,因为这就是WebForms抽象的工作方式。正如Keith所说,你可以使用Response.Redirect返回一个不同的页面,但你将返回一个页面。

这是ASP.NET MVC的美妙之处,我推荐它通过WebForms。

对于WebForms,URL指的是服务器应返回的资源。

使用ASP.NET MVC,URL描述了对控制器的指令。