.net 里的ashx跟java里的servlet类似,可以不用管html之类的东西。
新建一个空的asp.net项目,不是空的也可以。
添加一个web handler codebehide:
wtf.ashx
<%@ WebHandler Language="C#" Class="testashx.wtf" %>
wtf.ashx.cs
//------------------------------------------------------------------------------ //
// 此代码由工具生成。 // 运行时版本:4.0.30319.18444 // // 对此文件的更改可能会导致不正确的行为,并且如果 // 重新生成代码,这些更改将会丢失。 //
//------------------------------------------------------------------------------ namespace testashx { using System; using System.Web; using System.Web.UI; public class wtf : System.Web.IHttpHandler { public bool IsReusable { get { return false; } } public void ProcessRequest (HttpContext context) { context.Response.Write (typeof(wtf)); } } }
也可以不是codebehide,只要继承System.Web.IHttpHandler,如添加一个类
ta.cs
using System; using System.Web; namespace testashx { public class ta : System.Web.IHttpHandler { public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { context.Response.Write("aaa"); } } }
这里测试用的是jexus,在服务器上新建部署目录/home/www/testashx,把编译的bin拷到这个目录下,把wtf.ashx也拷到这个目录下,把Default.aspx也拷到这个目录下。
来一个:
[root@centos7 ~]#curl 127.0.0.1:/wtf.ashx
testashx.wtf [root@centos7 ~]#
可以像
curl 127.0.0.1:/Default.aspx
一样愉快地访问了。
如果不是codebehide,在web.config 的
里加映射,那么前面加的那个ta.cs类,就这样:
试下:
curl 127.0.0.1:/tmd
返回:
[root@centos7 ~]# curl 127.0.0.1:/tmd aaa [root@centos7 ~]#
所以,ashx文件不是必须的。
[root@centos7 tashx]# ll total 12 drwxr-xr-x. 2 root root 25 Sep 12 21:55 bin -rw-r--r--. 1 root root 393 Sep 12 21:11 Default.aspx -rw-r--r--. 1 root root 1192 Sep 12 22:08 web.config -rw-r--r--. 1 root root 57 Sep 12 21:41 wtf.ashx [root@centos7 tashx]#
bin下有这些
[root@centos7 tashx]# ll bin total 8 -rw-r--r--. 1 root root 4608 Sep 12 21:54 testashx.dll [root@centos7 tashx]#
哦,jexus配置是这样的:
[root@centos7 jexus]# pwd /usr/jexus [root@centos7 jexus]# ls def.py jwsHttpd.exe.so jxHost2.dll state2.conf jws jwsLog.exe jxHost2.dll.so state4.conf jws.conf jwsState.exe jxHost.dll jws.exe jxAspx2.dll jxHost.dll.so jwsHttpd2.exe jxAspx2.dll.so log jwsHttpd2.exe.so jxAspx.dll os.def cron jwsHttpd.exe jxAspx.dll.so siteconf [root@centos7 jexus]# cd siteconf/ [root@centos7 siteconf]# ls default tashx [root@centos7 siteconf]# cat tashx # # Web Site: CM_MC_UNIVERSAL # port=28888 root=/ /home/www/tashx hosts=* # addr=0.0.0.0 # CheckQuery=false # NoLog=true # NoFile=/index.aspx # Keep_Alive=false # UseGZIP=true # UseHttps=true # DenyFrom=192.168.0.233, 192.168.1.*, 192.168.2.0/24 # AllowFrom=192.168.*.* # DenyDirs=~/cgi, ~/upfiles # indexes=myindex.aspx # rewrite=^/.+?\.(asp|php|cgi|pl|sh)$ /index.aspx # reproxy=/bbs/ http://192.168.1.112/bbs/ # Jexus php fastcgi address is '/var/run/jexus/phpsvr' # # fastcgi.add=php|socket:/var/run/jexus/phpsvr # php-fpm listen address is '127.0.0.1:9000' # fastcgi.add=php|tcp:127.0.0.1:9000 [root@centos7 siteconf]#
哦,添加完项目jexus 的host文件后,要重启jexus,就是这个:
[root@centos7 siteconf]# ll /usr/jexus/siteconf/tashx -rw-r--r--. 1 root root 767 Sep 12 21:20 /usr/jexus/siteconf/tashx [root@centos7 siteconf]#
重启:
[root@centos7 jexus]# ./jws Usage: jws {start|stop|restart|regsvr|status|-v} [root@centos7 jexus]# pwd /usr/jexus [root@centos7 jexus]# ./jws restart Restarting ... OK [root@centos7 jexus]#
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/212905.html原文链接:https://javaforall.net
