本文介绍了会议ASHX设置和获取上的aspx这届会议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下code是工作在IE上而不是在Firefox浏览器。
下面code是* .ashx的文件中设置会话。
公共类上传:IHttpHandler的,IRequiresSessionState
{
公共字符串PATH = System.Web.HttpContext.Current.Request.MapPath(..)+ @\\ UploadFiles \\;
公共字符串preFIX =ANNUAL_;
公共无效的ProcessRequest(HttpContext的背景下)
{
HttpPostedFile文件= context.Request.Files [Filedata上];
file.SaveAs(PATH + preFIX + file.FileName);
HttpContext.Current.Session [文件名] = file.FileName;
context.Response.Write(1);
}
}
在* .aspx文件获取会话如下。尽管我可以设置值成* ashx的文件中的会话,会话值为null时会在* .aspx文件到达。
我怎样才能解决我的问题?能否请您提供任何解决我的问题呢?
使用System.Web.SessionState;
公共部分类frmImport:System.Web.UI.Page,IReadOnlySessionState
{
保护无效btnSave_Click(对象发件人,EventArgs的发送)
{
。字符串TEMP = HttpContext.Current.Session [文件名]的ToString();
}
}
解决方案
将下面的code Web.Config中
<结构>
<&的System.Web GT;
<的sessionState模式=是InProc无Cookie =真/>
问题已经消失了!
The following code is working on IE but not on Firefox.The following code is setting session on *.ashx file.
public class Upload : IHttpHandler, IRequiresSessionState
{
public string PATH = System.Web.HttpContext.Current.Request.MapPath("..") + @"\UploadFiles\";
public string prefix = "ANNUAL_";
public void ProcessRequest(HttpContext context)
{
HttpPostedFile file = context.Request.Files["Filedata"];
file.SaveAs(PATH + prefix + file.FileName);
HttpContext.Current.Session["filename"] = file.FileName;
context.Response.Write("1");
}
}
Getting session in *.aspx file is as follows. Even though I can set value into the sessions in *ashx file, the session value is null when session arrives in the *.aspx file.How can I solve my problem? Could you please give any solution about my problem?
using System.Web.SessionState;
public partial class frmImport : System.Web.UI.Page, IReadOnlySessionState
{
protected void btnSave_Click(object sender, EventArgs e)
{
string temp = HttpContext.Current.Session["filename"].ToString();
}
}
解决方案
Put the following code in Web.Config
<configuration>
<system.web>
<sessionState mode="InProc" cookieless="true" />
The problem has gone !
这篇关于会议ASHX设置和获取上的aspx这届会议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!