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;
}
jgauffin
  • 95,399
  • 41
  • 227
  • 352
user650474
  • 13
  • 1
  • 4

3 Answers3

2

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

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

John Gietzen
  • 45,925
  • 29
  • 140
  • 183
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>
Darin Dimitrov
  • 960,118
  • 257
  • 3,196
  • 2,876
0

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

Josh Pearce
  • 3,229
  • 1
  • 20
  • 24