Rajadurai Azhagudurai
Rajadurai Azhagudurai

Reputation: 83

Azure App Service File.ReadAllText returns File not found exception but file exist in that location

We have email templates as .cshtml file format in under the Content/Templates folder. We read that template using File.ReadAllText() then apply our model value then send that mail to the particular user. It works fine in locally hosted machine. When I host my asp.net mvc app in Azure App service file not found exception throws.

private string GetTemplateContent(string templatePath)
    {
        var templateContent = string.Empty;
        var path = GetAbsoluteTemplatePath(templatePath);

        try
        {
            templateContent = File.ReadAllText(Path.GetFullPath(path));
        }
        catch (Exception ex)
        {
            Log exception
        }

        return templateContent;
    }

Path in Azure "D:\home\site\wwwroot\Content\Templates\ScheduleTemplate.cshtml"

I ensured file exist in that location.

Can you help me why this is happening?

Upvotes: 1

Views: 1427

Answers (1)

Rajadurai Azhagudurai
Rajadurai Azhagudurai

Reputation: 83

This is Azure App service issue. From this Thread we found the solution. Add node in Application Setting

Key: WEBSITE_DYNAMIC_CACHE (all capitals) Value: 0

Upvotes: 4

Related Questions