ashx 文件可以嵌入JavaScript脚本吗?

cdcopyright 2009-03-03 09:43:56
我想在ashx文件执行一段脚本,可以吗?能示例说明下怎么做吗?
...全文
461 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wfyfngu 2009-03-03
  • 打赏
  • 举报
回复
把 ashx 改为 aspx
gongsun 2009-03-03
  • 打赏
  • 举报
回复
呵呵...
huzi01245 2009-03-03
  • 打赏
  • 举报
回复
不能。ashx就是个服务器端程序
zhxhdean 2009-03-03
  • 打赏
  • 举报
回复
不可以的。ashx是一般处理文件,等同于aspx.cs
Roc_Lee 2009-03-03
  • 打赏
  • 举报
回复
不能。ashx就是个服务器端程序
gaozhigang 2009-03-03
  • 打赏
  • 举报
回复
不可以,它是一个一般处理程序
  • 打赏
  • 举报
回复
不能执行,不过你完全不用在ashx文件里执行js脚本,可以在ashx文件以外执行!
ashx文件就相当于aspx文件的后台代码页面aspx.cs
他主要执行服务器事件,所以不能执行js脚本
namhyuk 2009-03-03
  • 打赏
  • 举报
回复
试了一下,楼上的方法确实可以。


public class Handler1 : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type='text/javascript'>");
sb.Append("alert('test')");
sb.Append("</script>");
context.Response.Write(sb.ToString());
}

public bool IsReusable
{
get
{
return false;
}
}
}
lovehongyun 2009-03-03
  • 打赏
  • 举报
回复
ashx就是一个IHttpHandler

你说的嵌入是什么意思?

不过可以输出js脚本
如:
<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("<script>alert('Hello World')</script>");
}

public bool IsReusable {
get {
return false;
}
}

}
reke2000 2009-03-03
  • 打赏
  • 举报
回复
你可以把要执行的脚本写出来,比如

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
context.Response.Write("<script lanaguage='javascript'>alert('Hello');</script>");
}


这要再打开ASHX的时候它就执行了
sxmonsy 2009-03-03
  • 打赏
  • 举报
回复
用.aspx

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧