Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
685 views
in Technique[技术] by (71.8m points)

c# - 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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...