The HTTP verb POST used to access path is not allowed

1

I am not using URL Rewriting, my app works fine until I try to hit a .PDF file or even a .TXT file via a link that I have dynamically generated into the PostBackUrl of a LinkButton. The path is correct.

I have thoroughly researched this issue on here and most of the issues are with people using a POST action or not or the URL Rewriting, which I am not.

In IIS Error looks like:

Server Error in Application "DEFAULT WEB SITE/EVENTS"Internet Information Services 7.5
Error Summary
HTTP Error 405.0 - Method Not Allowed
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used. Detailed Error Information
Module StaticFileModule 
Notification ExecuteRequestHandler 
Handler StaticFile 
Error Code 0x80070001 
Requested URL http://localhost:80/Events/EventDocs/48ea946f-e948-e011-ad73-00155d0e670b/2011.pdf 
Physical Path C:\projects\Events\EventDocs\48ea946f-e948-e011-ad73-00155d0e670b\2011.pdf 

Code to dynamically generate the url to click to is here:

public void DocumentsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
        LinkButton LinkToDoc = (LinkButton)e.Item.FindControl("LinkToDoc");                     
        Label FileNameLabel = (Label)e.Item.FindControl("FileNameLabel");
        LinkToDoc.PostBackUrl = "~/EventDocs/" + SessionValue.EventId.ToString() + "/"  + FileNameLabel.Text;
        LinkToDoc.Text = FileNameLabel.Text;
}
c#
.net
asp.net
asked on Stack Overflow Mar 8, 2011 by user650474 • edited Mar 8, 2011 by jgauffin

3 Answers

2

Don't use a LinkButton. Use a HyperLink control.

The HyperLink control has a NavigateUrl property that you can use.

answered on Stack Overflow Mar 8, 2011 by John Gietzen
1

When you use the PostBackUrl property of a LinkButton there is a POST verb being used. Quote from the documentation:

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.

So I would recommend you using a normal hyperlink:

<a href="<%= ResolveUrl("~/files/foo.pdf") %>">foo.pdf</a>
answered on Stack Overflow Mar 8, 2011 by Darin Dimitrov
0

There's some other property on a link button you want to set. Not PostBackUrl, because, as the name suggests, it Posts!

answered on Stack Overflow Mar 8, 2011 by Josh Pearce

User contributions licensed under CC BY-SA 3.0