我在Page_Load中写了从数据库中取二进制流,并根据fileType的类型(doc文档的是:application/msword,图片的是:image/pjpeg)写到新的WEB中,当类型是image/pjpeg的时候,所有都正常,当类型是application/msword的时候,有些webClient打开的时候是正常的,是能用word打开并正常显示word文档的内容,但有些webClient打开的时候,是用word软件打开了,但却显示了Default.aspx里面的内容,后来我把前面两个if语句都蔽掉了,就正常了,但前面两个if语句是要使用的,是什么原因造成这样的情况呢?请各位指教一下,谢!
Page_Load:
if(Session["sesPowerID"] == null)
Response.Redirect("Default.aspx");
if((int)Session["sesPowerID"] < 1)
Response.Redirect("Default.aspx");string sql=...;
SqlConnection connection = new SqlConnection("...");
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
try
{
SqlDataReader dr = command.ExecuteReader();
if(dr.Read())
{
Response.Clear();
Response.AppendHeader("Content-Type",dr["fcFileType"].ToString());
Response.BinaryWrite((byte[])dr["fimContent"]);
}
dr.Close();
}
finally
{
connection.Close();
}
Page_Load:
if(Session["sesPowerID"] == null)
Response.Redirect("Default.aspx");
if((int)Session["sesPowerID"] < 1)
Response.Redirect("Default.aspx");string sql=...;
SqlConnection connection = new SqlConnection("...");
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
try
{
SqlDataReader dr = command.ExecuteReader();
if(dr.Read())
{
Response.Clear();
Response.AppendHeader("Content-Type",dr["fcFileType"].ToString());
Response.BinaryWrite((byte[])dr["fimContent"]);
}
dr.Close();
}
finally
{
connection.Close();
}
解决方案 »
- UpdatePanel与FileUpload的问题
- 用C#实现QQ栏目的功能---求救
- tablelayoutpanel刷新闪烁问题...
- dataset循环插入数据问题请教?
- MSXML2和System.XML的问题
- 关于清除cookie的问题
- c#Winfrom ,两个数组间怎么相乘
- winform调用控制台程序的问题
- C# Socket.Receive 得到的数据,都是一个或多个完整的tcp包吗?
- 怎样从SQL SERVER DATABASE 中取出类型为IMAGE 的文件?高手救命呀!!
- 读卡器的读写
- 我只想实现用鼠标来移动datagrid的列的宽度。如何做呢,能否给我具体点的代码吗?(不是在winform)
后面加上
Response.End();
或者试试Response.Write("<script>location.href='Default.aspx'";</script>);
if(Session["sesPowerID"] == null)//把这句蔽掉会就正常
{
Response.Redirect("Default.aspx");
}
你把这两个写在一起试试。
1.
try
{
if((int)Session["sesPowerID"] < 1){}
}
finally
{Response.Redirect("Default.aspx");}2.把下面的语句放在else中
但从语句上来看应该是正确的,但就是出现问题,奇怪!!!
所以你搞清楚你的问题先:首先是出现错误页面是不是正常的。如果不正常,例如明明应该有Session却出现了错误页面,检查Coockie是否被禁用,或者Session超时。如果出现错误页面是正常的,例如你要测试Session超时的情况。不正常的是你的错误页面没有用IE打开而是用Word打开的。那么就按我上面所说的检查。
我把程序换成:
if(Session["sesPowerID"] == null)
Response.Redirect("Default.aspx")
else
{
......//发送http头,并用相应的程序打开
}
即使是换成上面这样,同样的操作,在部分的机子上运行就是用相应的程序(例如WORD)打开了文档,这是正常的,但在部分的机子上却用了相应的程序(例如WORD)打开了DEFAULT.ASPX的页面内容,也就是说Session["sesPowerID"]是不为空的时候,才会用到else里面的语句,但里面的语句是没有出现过default.aspx的东西呀,我都不知是和哪一方面有关系了...
if(Session["sesPowerID"] == null)
Response.Redirect("Default.aspx")
else
{
......//发送http头,并用相应的程序打开
}
如果Session为空的话就不应该会执行else里面的语句呀
Response 出类型,这时候启动word, 启动word后服务器会认为不在同一会话中,出现以上情形
只是猜测...
但为什么不同的机子上运行webClient会有不同的两种情况出现呢?
if((int)Session["sesPowerID"] < 1)
Response.Redirect("Default.aspx");
这句是正常的,也就是<1时,是会去default.aspx页的(这就是说是有cookie的支持),只是一旦加上Session==null时,就会出现这个问题
新手学习中,顶..........对WEB方面的东西很欠缺,很想多多学习呢!