解决方案 »

  1.   

    <%@ WebHandler Language="C#" Class="UploadHandler" %>using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.IO;
    using System.Web.SessionState;
    using System.Web;public class UploadHandler : IHttpHandler, IRequiresSessionState
    {    public void ProcessRequest(HttpContext context)
        {
       
            if (context.User.Identity.IsAuthenticated)
            {
                context.Response.ContentType = "text/plain";            HttpPostedFile file = context.Request.Files["Filedata"];
                string uploadPath = HttpContext.Current.Server.MapPath("/UpFiles") + "/pic/";
                string uploadPath2 = "/UpFiles" + "/pic/";
                if (file != null)
                {
                    //检测文件类型
                    if (ConfigurationManager.AppSettings["AllowedExtension"] != null)
                    {
                        string allowedExtension = ConfigurationManager.AppSettings["AllowedExtension"];
                    }                //检测目录是否存在 
                    if (!Directory.Exists(uploadPath))
                    {
                        //创建目录
                        Directory.CreateDirectory(uploadPath);
                    }                //保存上传文件
                    string filename = Guid.NewGuid() + Path.GetExtension(file.FileName);
                    uploadPath = uploadPath + filename;
                    uploadPath2 = uploadPath2 + filename;
                    file.SaveAs(uploadPath);                //返回上传成功的文件路径
                    //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失  
                    context.Response.Write(uploadPath2);
                }
            }
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }}这是asp.net的代码
    <script type="text/javascript">
        $(function () {
            $("#txturl_temp").uploadify({
                'uploader': "/Scripts/uploadify/uploadify.swf?v=' + new Date()",
                'script': "UploadHandler.ashx?v=' + new Date()",
                'cancelImg': "/Scripts/uploadify/cancel.png",
                'auto': true,
                'multi': false,
                'method': "get",
                'onError': function (event, queueId, fileObj, errorObj) {
                    alert(errorObj.type + " Error:" + errorObj.info);
                },
                'onComplete': function (event, queueId, fileObj, response, data) {
                    $("#txturl").val(response);
                    //$("#Spic_spic").attr("src", response);
                }
            });
        });
    </script>这是js 代码, 在本地一切正常,挂到服务器上就不行了
      

  2.   

     'script': "UploadHandler.ashx?v=' + new Date()",  这个.....你确认虚拟路径是正确的? 
    以前遇到过问题 vs创建的网站项目挂到服务器上之后虚拟路径异常,你在前面加../ ../../这些试试