The HTTP verb POST used to access path is not allowed

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:projectsEventsEventDocs48ea946f-e948-e011-ad73-00155d0e670b2011.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;
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

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

Method 2

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(" rel="nofollow noreferrer noopener"~/files/foo.pdf") %>">foo.pdf</a>

Method 3

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x