0

asp.netページでサーバーに画像をアップロードしています。コードは次のとおりです..

コード:

protected void Button2_Click1(object sender, EventArgs e)
        {

           //resimyolu = "~/r/" + FileUpload1.FileName;
           FileUpload1.SaveAs(Server.MapPath("~/r/a.png"));
           FileUpload1.SaveAs("d:/upresim/a.png");
           Image1.ImageUrl = "~/r/a.png";

        }

「r」フォルダーはプロジェクトの画像フォルダーです。実行時に「r」フォルダーに画像を追加すると、ローカル IIS で正常に動作しますが、プロジェクトを公開してサーバー (リモート サーバー) でホストするとWeb ページはブラウザーで開いていますが、button2 をクリックしてクライアント イメージ (クライアント ユーザーが自分のコンピューターから選択したもの) をプロジェクトに追加すると、以下のようなエラーが表示されます。

Runtime Error 
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
4

2 に答える 2

0

エラー メッセージに示されているように、web.config でカスタム エラーを無効にして、何が問題なのかを確認してください。

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>
于 2013-03-21T10:56:05.443 に答える
0

問題はこの行です。

FileUpload1.SaveAs("d:/upresim/a.png");

に変更すると役立ちます。

FileUpload1.SaveAs("d:\\upresim\\a.png");

コードの場合は、このようなハードコーディングされたパスを使用しないでください。マシンを変更すると、問題が発生します。Server.MapPath常により良い方法です。Web ディレクトリに保存したくない場合は、常に構成からベース パスを取得する必要があります。

于 2013-03-21T11:14:35.740 に答える