3

In my MVC application,@Html.ActionLink control works fine in my local machine. The actionlink redirects to the specified action. But when hosted in server, error "Resource not found. Please check the url" occurs.
View Code

@Html.ActionLink(" ", "ExportToQR", "WPCheckout", new { UserID = Request.QueryString["UserID"], Partnerid = Request.QueryString["Partnerid"] }, new { @class = "btnMakeQR" })

Class for button Image

 .btnMakeQR
        {
            background: url(../Images/Generate_QR_Code.png) no-repeat top left;
            display: block;
            width: 111px;
            height: 25px;
            text-indent: -9999px; 
        }

Controller Code

public class WPCheckoutController : Controller
{
     public ActionResult ExportToQR()
     {
       // logic to get encoding value for "qrcode" from database
        QRCodeEncoder encoder = new QRCodeEncoder();
        Bitmap img = encoder.Encode(qrcode);
        string path = Server.MapPath(@"/Images/QRCode.jpg");        
        img.Save(path, ImageFormat.Jpeg);        
        return base.File(path,"image/jpeg","OrderDetails.jpg");  

     }
}

What is the mistake in my code. ?. Any suggestions.
EDIT
This is the url, I get when hovering the button image.

 http://localhost/WPCheckout/ExportToQR?UserID=1013&Partnerid=ph111
kk1076
  • 1,740
  • 13
  • 45
  • 76
  • When you hover the link is the url correct? Whant's the error? – Stefano Altieri Apr 17 '13 at 10:36
  • 1
    @StefanoAltieri it's 404 i guess. are you sure the `Server.MapPath()` maps correctly? if not the case you could try `AppDomain.CurrentDomain.BaseDirectory.ToString()` – Vogel612 Apr 17 '13 at 10:40
  • @StefanoAltieri : yes. its 404 error. Please check my edit for url when hovered. – kk1076 Apr 17 '13 at 10:40
  • I meant what's the error in the url generated. Ie. what's the one you expect? what's the one you get? – Stefano Altieri Apr 17 '13 at 10:45
  • @StefanoAltieri the url which I get is the one I expected. But why it shows " 404 resource not found" error. The specific method is in controller. – kk1076 Apr 17 '13 at 10:48
  • So the problem is not the action link... I suppose you get the same error if you go to the url direcly... – Stefano Altieri Apr 17 '13 at 11:07
  • @StefanoAltieri : Yes. The actionlink is directed to the ExportToQR action in local system. But When hosted in IIS, this error occurs. – kk1076 Apr 17 '13 at 11:11

1 Answers1

1

Looking at your code, it seems that you create a file /Images/QRCode.jpg. I assume you mean ~/Images/QRCode.jpg?

In the first case the file will be named http://localhost/Images/QRCode.jpg which might not be readable by the IIS application due to restriction problems. In the latter case it will become http://localhost/WPcheckout/Images/QRCode.jpg.

Refering to this comment: /xxx and ~/xxx might be different.

Community
  • 1
  • 1
Stephen Reindl
  • 5,659
  • 2
  • 34
  • 38