本文介绍了如何在Aspx页面中访问Ashx页面会话值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

upload.ashx



upload.ashx

<%@ WebHandler Language="C#" Class="Upload" %>







using System;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Configuration;
using System.Web.SessionState;

public class Upload : IHttpHandler, IReadOnlySessionState
{     
         public void ProcessRequest (HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        context.Response.Expires = -1;       
      
        try
        {
            
         HttpPostedFile postedFile = context.Request.Files["Filedata"];
            
            string savepath = "";

            string tempPath = ConfigurationManager.AppSettings["Filedata"];
        
            savepath = context.Server.MapPath(tempPath);
            string filename = postedFile.FileName;
            if (!Directory.Exists(savepath))
                Directory.CreateDirectory(savepath);

            postedFile.SaveAs(savepath + @"\" + filename);
           
            context.Response.Write(tempPath + "/" + filename);
            context.Response.StatusCode = 200;
            if (postedFile != null)
            {
                context.Session["img"] = postedFile.FileName;
              
            }
            else
            {
                context.Session["img"] ="No File Uploaded";
              
            }
        }
        catch (Exception ex)
        {
            context.Session["img"] = "Throwed exception when uploading file";
            
            
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
 
}

Document.aspx.cs

if (Session["img"].ToString() != null)
{
   // this session return correct value in chrome 
  //but firefox it return null value only
}

Advance Thanks

推荐答案

if (Session["img"] != null)
{
   //put your logic here
}





希望,它有帮助:)



Hope, it helps :)


txtUploadFile.SaveAs(SharedPath + "\\" + Session["img"].ToString());



}


}


这篇关于如何在Aspx页面中访问Ashx页面会话值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 07:28