سؤال

ولدي معالج الموارد التي هي Response.WriteFile (اسم الملف) بناء على المعلمة التي تم تمريرها من خلال سلسلة استعلام مواقع المعلومات. أنا التعامل مع MIMETYPE بشكل صحيح، ولكن القضية هي في بعض المتصفحات، اسم الملف يأتي على النحو Res.ashx (اسم معالج) بدلا من MyPdf.pdf (ملف انا إخراج). يمكن للشخص يعلمني كيفية تغيير اسم الملف عند إرسالها مرة أخرى إلى الخادم؟ هنا هو رمز بلادي:

// Get the name of the application
string application = context.Request.QueryString["a"];
string resource = context.Request.QueryString["r"];

// Parse the file extension
string[] extensionArray = resource.Split(".".ToCharArray());

// Set the content type
if (extensionArray.Length > 0)
    context.Response.ContentType = MimeHandler.GetContentType(
        extensionArray[extensionArray.Length - 1].ToLower());

// clean the information
application = (string.IsNullOrEmpty(application)) ?
    "../App_Data/" : application.Replace("..", "");

// clean the resource
resource = (string.IsNullOrEmpty(resource)) ?
    "" : resource.Replace("..", "");

string url = "./App_Data/" + application + "/" + resource;


context.Response.WriteFile(url);
هل كانت مفيدة؟

المحلول

وتمتد من تعليق جويل، فإن الرمز الفعلي مظهرك شيئا من هذا القبيل:

context.Response.AddHeader("content-disposition", "attachment; filename=" + resource);

نصائح أخرى

ويجب أن تكون هذه آخر سكوت Hanselman مفيدة:
http://www.hanselman.com/blog/CommentView.aspx؟guid= 360

شكرا يا رفاق لإجابتك. يعمل رمز النهائية والشيكات لقوات الدفاع الشعبي.

if (extensionArray[extensionArray.Length - 1].ToLower() == "pdf")
    context.Response.AddHeader("content-disposition", 
        "Attachment; filename=" + resource);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top