2

私の目標は単純です: Web アプリから、ローカル サーバーの D ドライブのフォルダーに書き込みます。コードをローカルで (デバッガーで) 実行すると、フォルダーに美しく書き込まれます。コードを Web サーバーに発行すると、独自の D ドライブまたは共有フォルダーが表示されません。ばかげたものを含め、想像できるファイルパス文字列のすべての順列を試しました。

例:

filepath = "\\\\wsbliwad\\d\\Payroll\\PaperlessPay";
filepath = "\\wsbliwad\\d\\Payroll\\PaperlessPay";
filepath = "\\wsbliwad\d\Payroll\PaperlessPay";
filepath = "\\\\wsbliwad\\Payroll\\PaperlessPay";
filepath = "\\wsbliwad\Payroll\PaperlessPay";
filepath = @"\\wsbliwad\payroll\PaperlessPay";
filepath = @"\\\\wsbliwad\\payroll\\PaperlessPay";
filepath = @"\\wsbliwad\\payroll\\PaperlessPay";
filepath = @"\\wsbliwad\d\Payroll\PaperlessPay"

…他にも多数。

Response.Write ステートメントを使用して何が起こっているかを把握し、コードをローカルで実行すると、次のフィードバックが得られます。

Path one = \\wsbliwad\payroll\PaperlessPay
Exists = True
Path two = \\wsbliwad\\payroll\\PaperlessPay
Exists = True
Path one = \\\\wsbliwad\\payroll\\PaperlessPay
Exists = True
Host Name is CPU1476
AD User is ANVILCORP\DGray

そして、ファイルはフォルダーに書き込みます。

同じコードをデプロイすると、失敗する結果が得られます。

Path one = \\wsbliwad\payroll\PaperlessPay
Exists = False
Path two = \\wsbliwad\\payroll\\PaperlessPay
Exists = False
Path one = \\\\wsbliwad\\payroll\\PaperlessPay
Exists = False
Host Name is WSBLIWAD
AD User is ANVILCORP\dgray

ファイルは書き込まれません。

フォルダーに移動し、グループ内の必要なすべてのユーザーに明示的に書き込みアクセス許可を付与しました。おそらく、これは不適切に報告されたアクセス許可の問題であると考えています。そのような幸運はありません。

私が気付いた奇妙な点の 1 つは、response.write の最後の行で、ドメイン ユーザーをデバッガーで実行すると大文字になり、コードをデプロイすると小文字になることです。それが重要なのかどうかはわかりませんが、奇妙に思えます。

コードがデバッガーから共有フォルダーを表示できるのに、デプロイ時には表示されない理由はありますか?

DJ KRAZE のリクエストは以下のとおりです。

protected void btn_Export_Click(object sender, EventArgs e)
{

    DateTime mCheckDate = DateTime.Parse(tb_CheckDate.Text);
    int mPeriod = Int32.Parse(tb_Period.Text);


    try
    {
        string checkDateFormat = "MM/dd/yyyy";
        ReadOnlyCollection<IDataRow> dataRows = FlatFileExportWeb.PaperlessPay.GetPaperlessPayData(mPeriod.ToString(), mCheckDate.ToString(checkDateFormat));

        if (dataRows == null)
            return;

        IDataFormat format = new SimpleDataFormat(dataRows);

        string filepath = "";
        string machineName = System.Net.Dns.GetHostName();               
        if (machineName == "WSBLIWAD")
        {
            // This path does not work
            filepath = @"\\wsbliwad\d$\Payroll\PaperlessPay";
        }
        else
        {
            // this path works when debugging
            filepath = @"\\wsbliwad\payroll\PaperlessPay";
        }

        string filename = "PaperlessPay" + mCheckDate.ToString("MMddyyyy") + ".txt";

        new FileGenerator(filepath, filename).BuildFile(format);
        Response.Write("<br />&nbsp;&nbsp;&nbsp;Success!! The flat file has been written to " + filepath + @"\" + filename);
    }
    catch (Exception ex)
    {
        // Display any exceptions that may have been thrown.
        System.Web.HttpContext.Current.Response.Write(ex);
    }
}

... その後...

// Absolute path with concatenated filename
string mFilenameWithPath;

/// <summary>
/// Constructs a FileGenerator instance pointing to filepath\PaperlessPay\filename.
/// Will delete pre-existing file at this location.
/// </summary>
public FileGenerator(string filepath, string filename)
{
    if (!Directory.Exists(filepath))
        throw new DirectoryNotFoundException(filepath);

    mFilenameWithPath = filepath + @"\" + filename;

    if (File.Exists(mFilenameWithPath))
        File.Delete(mFilenameWithPath);
}


/// <summary>
/// Given an IDataFormat instance, BuildFile builds an output string.
/// It will then write this output string to the file specified within
/// the class, as passed into the constructor.
/// </summary>
/// <param name="format"></param>
public void BuildFile(IDataFormat format)
{
    // Make sure the format exists
    if (format == null)
        return;

    // Collect output string, and
    // write the string to filepath.
    using (StreamWriter writer = File.CreateText(mFilenameWithPath))
        writer.Write(format.Build());
}
4

3 に答える 3

1

トラックスは正しいです。実際、権限の問題であることが判明しました。2 つのシステムを接続し、Interface.Dev という名前のドメイン アカウントを作成しました。そのユーザーは書き込み権限を持つセキュリティ プロパティにリストされていましたが、何らかの理由で書き込みではなくフル コントロールが必要でした。

その道をしつこく指摘してくれた Traxs に感謝します。エラーメッセージはひどく誤解を招くものでした。そうでなければ、パス情報と永遠に戦い続けていたでしょう。

于 2013-08-02T18:24:33.590 に答える
1

そのパスへの書き込みアクセス権がないことが原因である可能性があります。

于 2014-06-02T17:50:50.630 に答える