Where in ASP.NET-MVC 5 application DataDirectory is defined

1.4k Views Asked by At

Where in ASP.NET-MVC 5 application DataDirectory is defined? By this I mean where is(exactly the line) method which sets it invoked inside the ASP.NET-MVC 5 appliation. I look for exact line which sets it.

I have seen this:

internal static string ExpandDataDirectory(string keyword, string value, ref string datadir)
{
    string text = null;
    if (value != null && value.StartsWith("|datadirectory|", StringComparison.OrdinalIgnoreCase))
    {
        string text2 = datadir;
        if (text2 == null)
        {
            // 1st step!
            object data = AppDomain.CurrentDomain.GetData("DataDirectory");
            text2 = (data as string);
            if (data != null && text2 == null)
                throw ADP.InvalidDataDirectory();

            if (ADP.IsEmpty(text2))
            {
                // 2nd step!
                text2 = AppDomain.CurrentDomain.BaseDirectory;
            }
            if (text2 == null)
            {
                text2 = "";
            }
            datadir = text2;
        }

        // 3rd step, checks and normalize
        int length = "|datadirectory|".Length;
        bool flag = 0 < text2.Length && text2[text2.Length - 1] == '\\';
        bool flag2 = length < value.Length && value[length] == '\\';
        if (!flag && !flag2)
        {
            text = text2 + '\\' + value.Substring(length);
        }
        else
        {
            if (flag && flag2)
            {
                text = text2 + value.Substring(length + 1);
            }
            else
            {
                text = text2 + value.Substring(length);
            }
        }
        if (!ADP.GetFullPath(text).StartsWith(text2, StringComparison.Ordinal))
            throw ADP.InvalidConnectionOptionValue(keyword);
    }
    return text;
}

but where this method is invoked?

1

There are 1 best solutions below

1
On

By default in Web Application, |DataDirectory| is application's App_Data folder.

enter image description here

Unless you explicit set it as - AppDomain.CurrentDomain.SetData("DataDirectory", Path)

Source: Working with local databases