0

When i am writing the code..

 <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
        PostBackUrl="~/Biodata.xls" Text="Button" />

 protected void Button1_Click(object sender, EventArgs e)
{
    Server.Transfer("a.aspx");
}

I am getting the error given below.

The HTTP verb POST used to access path '/WebSite4/Biodata.xls' is not allowed.

Here i am trying to redirect the page to another after download the xls file.

BradBrening
  • 5,418
  • 25
  • 30
SoumitaP
  • 63
  • 2
  • 5
  • 13

1 Answers1

1

You're looking at this part:

Server.Transfer("a.aspx");

But the error message is referring to this part:

PostBackUrl="~/Biodata.xls"

Don't post back to an xls file. That's not the way to download something. And you can't "download something and then redirect somewhere else". That's not how HTTP requests and responses work.

The browser requested your page. You are returning a response.

  1. You can turn the job over to a.aspx. Then it's the job of a.aspx to return a response.

  2. Or else you can respond with the xls file itself, with an appropriate content type and disposition in the HTTP headers. You'll be using something like Response.BinaryWrite, something like this. Then it's up to the browser what do do with it. The browser could open it using something like Excel, or it could offer the user a chance to save the file.

You can't do both of these things. You have to choose.

Also see here and here for other related problems.

Community
  • 1
  • 1
criticalfix
  • 2,870
  • 1
  • 19
  • 32