0

I have a web application asp.net mvc. In this application, I use DataTables that I configure like that to have the french language:

<script type="text/javascript">
    $(function () {
        $('table#list').DataTable({
            'language': {
                'url': '@Url.Content("~/Content/datatables-i18n.fr.json")'
            }
        })
    });
</script>

When I test my application locally, it works, I have the datatable in French but when I publish my application (with Visual Studio), it's not working anymore. I have this error :

Failed to load resource: the server responded with a status of 404 (Not Found)

But if I pass the cdn url instead of my file, it works locally and also after publishing :

    <script type="text/javascript">
    var table;
    $(function () {
        table = $('table#list').DataTable({
            language: {
                'url': 'http://cdn.datatables.net/plug-ins/1.10.16/i18n/French.json'
            }
      })
</script>

Do you know why the file is not find after publishing ?

1
  • Hi, maybe it's an obviouse question but are you positive that Visual Studio is publishing your localized files (I'm talking about solution explorer -> properties of the /Content/datatables-i18n.fr.json -> copy in output folder)? Commented Sep 27, 2017 at 9:04

1 Answer 1

2

If Url.Content working properly on local but not in production (publish) & you're sure the file exists on the corresponding folder (i.e. [application folder]\Content), possibly it related to registered IIS file type issue. You can add json MIME type to the IIS using these steps:

1) Select your site in Sites section, choose MIME Types option in IIS category.

2) Use Add to show "Add MIME Type" box.

3) Add proper MIME type for JSON file extension as application/json as shown in this image, then click OK (possible requires restarting your site to apply this change):

enter image description here

If both local & production environment returning 404 for Url.Content path, it is possible that the problem originated from browser security issue, since language configuration options require AJAX callback and some browsers disallow AJAX request to retrieve local files by using file:// path (more info). When this becomes your current issue, nothing else than using DataTables CDN URL like http://cdn.datatables.net/plug-ins/1.10.16/i18n/French.json since you can't control client's browser security settings.

Similar issues:

How to resolve language file URL for Jquery datatables in ASP.NET

how to change language for DataTable

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, thanks, it was a problem of MIME type. I just added this line "<mimeMap fileExtension=".json" mimeType="application/json" />" in the web.config file under "<system.webServer> <staticContent>".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.