开发者

"The HTTP verb used to access this page is not allowed" on an .msi Download via a LinkButton

Ive got a asp.net web application and have just added a a new link to allow users to download

<asp:LinkButton ID="lnkDownload" runat="server" Text="Download" 
     PostBackUrl="/download/releases/program.msi" onclick="lnkDownload_Click" 
     ToolTip="Download">
</asp:LinkButton>

But when I click the link I ge开发者_如何学JAVAt HTTP Error 405 - The HTTP verb used to access this page is not allowed.

I assume I need to change some setting in IIS (IIS 6) any one know what ?


The PostBackURL property of the asp:LinkButton is the wrong choice here. See the "Remarks" section of the documentation I linked:

The PostBackUrl property allows you to perform a cross-page post using the LinkButton control. Set the PostBackUrl property to the URL of the Web page to post to when the LinkButton control is clicked. For example, specifying Page2.aspx causes the page that contains the LinkButton control to post to Page2.aspx. If you do not specify a value for the PostBackUrl property, the page posts back to itself.

You can't/shouldn't use it to trigger a file download. The more appropriate control would be:

<asp:HyperLink runat="server" ID="lnkDownload" runat="server" Text="Download"
     NavigateUrl="/download/releases/program.msi"></asp:HyperLink>

You could also use a "plain" <a href="/download/releases/program.msi></a>.


The page is POSTing to the MSI which will be disallowed in the Handlers section of IIS. Rather than using a LinkButton, try using an HTML link (<a> tag), this will perform a GET to the .msi file.

Alternatively, if you need POST, configure your IIS appropriately.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜