0
ブラウザでpdfファイルを表示したいのですが、次のコードはlocalhostで動作しますが、devサーバでは動作しません。Pdfはローカルではなくdevにレンダリングする
また、このPDFファイルを新しいウィンドウ/タブに表示するには、グリッドビューのリンクボタンをクリックしてください。
protected void lnkBtn_grid_View_Command(object sender, CommandEventArgs e)
{
try
{
var fileName = e.CommandArgument.ToString();
var normalTextByte=Encoding.UTF8.GetBytes(fileName);
var encryptedFile = MachineKey.Encode(normalTextByte, MachineKeyProtection.All);
Response.Redirect("~/statementfilesviewer.aspx?filename=" + Server.UrlEncode(encryptedFile));
}
catch (Exception ex)
{
Error.Log(ex);
}
}
private void ReadPdfFile(string filename)
{
string keyName = "";
try
{
string prefix = ConfigurationManager.AppSettings["Environment"] + "/StatementFiles/";
keyName = prefix + SessionFacade.DbId + "/" + _intArtistId + "/" + filename;
IAmazonS3 client;
using (client = new AmazonS3Client())
{
var request = new GetObjectRequest
{
BucketName = ConfigurationManager.AppSettings["BucketName"],
Key = keyName
};
string cwrFilePath;
using (GetObjectResponse response = client.GetObject(request))
{
cwrFilePath = @"~/PDFs/" + filename.Replace(" ", "_").Replace("-", "_");
if (File.Exists(Server.MapPath(cwrFilePath)))
File.Delete(Server.MapPath(cwrFilePath));
if (!File.Exists(Server.MapPath(cwrFilePath)))
{
response.WriteResponseStreamToFile(Server.MapPath(cwrFilePath));
}
}
if (File.Exists(Server.MapPath(cwrFilePath)))
{
//Literal1.Text = " <object data=\"/PDFs/" + filename.Replace(" ", "_").Replace("-", "_") + "\" type=\"application/pdf\" height=\"600\" width=\"99%\" style=\"border: none;\"><embed src=\"/PDFs/" + filename.Replace(" ", "_").Replace("-", "_") + "\" type=\"application/pdf\" height=\"600\" width=\"99%\" style=\"border: none;\" /></object>";
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
//Response.WriteFile(cwrFilePath);
Response.WriteFile(Server.MapPath(cwrFilePath));
Response.End();
}
else
Response.Write("File does not exists. Please contact to support team.");
}
}
catch (Exception)
{
Response.Write("File does not exists. Please contact to support team.");
EmailingDal.SendEmail("File does not exists on S3 server.", keyName);
}
}
おそらくファイルパスエラーです。 keyNameに表示される例外メールは何ですか? – mjw
*「動作していません」*は非常に曖昧です...正確に動作していないのは何ですか?何かエラーが出ますか?それとも期待どおりに出力されていませんか?あなたの状況や問題をより簡単に理解できるようにできるだけ多くの情報を提供してください。 – bassfader
エラーも例外もなく、pdfファイルをレンダリングせずにstatementfilesviewer.aspxに移動するだけです –