【问题标题】:Where in ASP.NET-MVC 5 application DataDirectory is defined在 ASP.NET-MVC 5 应用程序 DataDirectory 中定义的位置
【发布时间】:2015-01-03 04:22:28
【问题描述】:

在 ASP.NET-MVC 5 应用程序中 DataDirectory 是在哪里定义的?我的意思是 where is(exactly the line) 方法设置它在 ASP.NET-MVC 5 应用程序中调用。我寻找设置它的确切线。

我看过这个:

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;
}

但是这个方法在哪里被调用呢?

【问题讨论】:

    标签: .net entity-framework datadirectory


    【解决方案1】:

    默认情况下,在 Web 应用程序中,|DataDirectory| 是应用程序的 App_Data 文件夹。

    除非您明确将其设置为 - AppDomain.CurrentDomain.SetData("DataDirectory", Path)

    来源:Working with local databases

    【讨论】:

    • 我都知道。我要求在新的 ASP.NET-MVC 项目中将 DataDirectory 定义为 App_Data 的显式代码。
    猜你喜欢
    • 2016-09-11
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 2022-11-24
    • 2015-02-09
    • 1970-01-01
    相关资源
    最近更新 更多