3
function girisAjaxKontrol() {
var kullanici = { 'kullaniciAdi': $('#username').val(), 'hidden': $('#password').val() };
$.ajax({
    url: '/Giris/GirisGecerliMi',
    type: 'POST',
    data: kullanici,
    success: girisAjaxReturn,
    error: function (error, textstatus) {
        JSON.stringify(error);
        errorMessage($("div.girisSubmit input"), JSON.stringify(error), false);            
    }
});

}

This function gets the error below(it was working before deployment). The website is an Asp .Net MVC4 website on local IIS 7.5; I searched a lot but couldn't solve yet.

Server Error in Application \"DEFAULT WEB SITE\"

HTTP Error 404.0 - Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Module: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error Code: 0x80070002

Requested URL   http://localhost:80/Giris/GirisGecerliMi
Physical Path   C:\\inetpub\\wwwroot\\Giris\\GirisGecerliMi
Logon Method    Anonymous
Logon User  Anonymous   
tereško
  • 58,060
  • 25
  • 98
  • 150
serefbilge
  • 1,654
  • 4
  • 29
  • 55

1 Answers1

5
url: '/Giris/GirisGecerliMi',

should not be hardcoded like this. You should use url helpers to generate this url. The reason for that is because when you deploy your application in IIS there's a virtual directory name that you should take into account, so the correct url is:

url: '/MyAppName/Giris/GirisGecerliMi',

But by hardcoding the url as you did there's no way for this to work. In ASP.NET MVC you should always use url helpers such as Url.Action to generate the url to a given controller action as those helpers take into account not only your routing definitions but things like virtual directory names as well.

So the correct way is to have this url generated server side and passed as argument to the girisAjaxKontrol function:

function girisAjaxKontrol(url) {
    var kullanici = { 'kullaniciAdi': $('#username').val(), 'hidden': $('#password').val() };
    $.ajax({
        url: url,
        type: 'POST',
        data: kullanici,
        success: girisAjaxReturn,
        error: function (error, textstatus) {
            JSON.stringify(error);
            errorMessage($("div.girisSubmit input"), JSON.stringify(error), false);            
        }
    });
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Because when debugging there's no virtual directory, you are hosting your application directly in the Visual Studio's built-in web server and the address is `http://localhost:12345/Giris/GirisGecerliMi`. But when you host in IIS the address is now `http://localhost:80/MyAppName/Giris/GirisGecerliMi` where `MyAppName` is obviously the virtual directory name you configured in IIS. – Darin Dimitrov Jun 20 '12 at 13:54
  • How can I use Url.Action inside external js file, or is it possible? – serefbilge Jun 20 '12 at 14:01
  • I think I found a way of using Url.Action inside external js file, as in another [post](http://stackoverflow.com/questions/9922041/use-seprate-js-file-and-use-url-helpers-in-it-with-asp-net-mvc-3-and-razor-view/). Thanks a lot, I admire you, keep your way Darin. – serefbilge Jun 20 '12 at 14:10