WebDev.WebServer40.exe改造,自己制作轻量级asp.net网站IIS服务

       大学玩asp.net时就发现VS在Debug时会起一个web服务,这东西也太神奇了服务起得这么快,而相对于IIS又这么渺小。

       前几个月在用phonegap+jqmobi(被inter收购后叫App Framework)做手机应用开发。用dreamweaver CS6的云编译确实挺方便的,但是写代码的话还是比较喜欢VS的代码联想。本地调试时,点击又启动了这个web服务。

       再后来要开发一个在WPF嵌入网页的控件,果断用WebBrowser控件简单地封装了一下,这样发现当只是打开本地的html页面时就会弹出安全阻止信息,需要手动点一下允许,度娘的各种改IE设置就是没用,最后发现通过访问web服务返回的页面就不会弹出该提示了。第一反映就是用VS自带的这个来实现,但是托盘会弹气泡等,所以不得不改造下了。

 用360查看该端口定位文件

 

 

151KB,还绿色版,这也太牛了。但是但我用局域网地址进行访问时就发现不可访问,这是为什么呢?有点太可惜了所以就上网找了这个exe的相关资料,有人已经修改了可以局域网访问了,但是他改的东西下载下来报错,于是就决定自己动手进行修改。

仔细阅读之前各位大神写的文章后,综合优化了一下,终于出现了,真正绿色版(.NET 4.0),win8下完美运行:

纯正绿色版,无任何微软信息

 

1.修改过程


  把WebDev.WebServer40.EXE拖到ILSpy.exe里进行反编译成项目(本人比较支持免费软件)

  同样也反编译应用的WebDev.WebHost40成项目

server里对host的引用删了,重新引用刚反编译的项目。

修改Microsoft.VisualStudio.WebHost.Server里的方法Start(),修改的代码如下:

 

复制代码
if (Socket.OSSupportsIPv6)
            {
                try
                {
                    this._socketIpv6 = this.CreateSocketBindAndListen(AddressFamily.InterNetworkV6, IPAddress.IPv6Any, this._port);
                }
                catch (SocketException ex)
                {
                    if (ex.SocketErrorCode == SocketError.AddressAlreadyInUse || !flag)
                    {
                        throw;
                    }
                }
            }
            if (flag)
            {
                try
                {
                    this._socketIpv4 = this.CreateSocketBindAndListen(AddressFamily.InterNetwork, IPAddress.Any, this._port);
                }
                catch (SocketException)
                {
                    if (this._socketIpv6 == null)
                    {
                        throw;
                    }
                }
            }
复制代码

 

 Microsoft.VisualStudio.WebHost.RequestTryParseRequest()方法一个判断注释掉

复制代码
private bool TryParseRequest()
        {
            this.Reset();
            this.ReadAllHeaders();
            //if (!this._connection.IsLocal)
            //{
            //    this._connection.WriteErrorAndClose(403);
            //    return false;
            //}
            if (this._headerBytes == null || this._endHeadersOffset < 0 || this._headerByteStrings == null || this._headerByteStrings.Count == 0)
            {
                this._connection.WriteErrorAndClose(400);
                return false;
            }
复制代码

这时候F6编译一下发现 Microsoft.VisualStudio.WebHost.NtlmAuth下的Authenticate()方法报一大堆Fixed关键字错误,做如下修改骗过编译器

复制代码
fixed (SecHandle* lptr = (&this._securityContext))
            {
                IntPtr* ptr = (IntPtr*)lptr;
                fixed (SecBuffer* lptr2 = (&this._inputBuffer))
                {
                    IntPtr* ptr2 = (IntPtr*)lptr2;
                    fixed (SecBuffer* lptr3 = (&this._outputBuffer))
                    {
                        IntPtr* ptr3 = (IntPtr*)lptr3;
                        fixed (byte* lptr4 = (&array[0]))
                        {
                            IntPtr* ptr4 = (IntPtr*)lptr4;
                            fixed (byte* lptr5 = (&array2[0]))
                            {
                                IntPtr* ptr5 = (IntPtr*)lptr5;
                                IntPtr phContext = IntPtr.Zero;
                                if (this._securityContextAcquired)
                                {
                                    phContext = (IntPtr)((void*)ptr);
                                }
复制代码

Microsoft.VisualStudio.WebHost.ConnectionGetHost()方法里加入如下代码(要把WebDev.WebHost40.dll复制到站点目录的bin目录下):

复制代码
lock (this._lockObject)
                {
                    host = this._host;
                    if (host == null)
                    {
                        //复制当前dll到站点目录
                        Assembly myAss = Assembly.GetExecutingAssembly();
                        string assUrl = myAss.Location;
                        if (!File.Exists(this._physicalPath + "\\bin\\" + myAss.FullName.Split(',')[0] + ".dll"))
                        {
                            if (!Directory.Exists(this._physicalPath + "\\bin"))
                            {
                                Directory.CreateDirectory(this._physicalPath + "\\bin");
                            }
                            File.Copy(assUrl, this._physicalPath + "bin\\" + myAss.FullName.Split(',')[0]+".dll");
                        }
                       
                        string text = (this._virtualPath + this._physicalPath).ToLowerInvariant();
                        string appId = text.GetHashCode().ToString("x", CultureInfo.InvariantCulture);
                        this._host = (Host)this._appManager.CreateObject(appId, typeof(Host), this._virtualPath, this._physicalPath, false);
                        this._host.Configure(this, this._port, this._virtualPath, this._physicalPath, this._requireAuthentication, this._disableDirectoryListing);
                        host = this._host;
                    }
                }
复制代码

最后一步,为WebDev.WebHost40.dll添加签名,不然运行时还是会去加载自带的WebDev.WebHost40.dll

编译一下,这样运行WebDev.WebServer40.EXE加载本地路径就可以局域网访问了。

为了简单易用,我用WPF做了窗口来方便WebServer40.EXE启动参数的传递,在传递参数时多加入一个“/silent:true”参数就可以静默运行了。具体怎么启动怎么传参具体我就不说了,参看Process这个类。

 运行如下:

 

 

下载地址:http://files.cnblogs.com/tong-tong/TTWebServer.zip

参考文献: http://www.cnblogs.com/huigll/archive/2011/02/25/1851112.html

  

后记


近来在各种房贷、老婆贷的压力下接了各种私活,各种加班,各种被坑,不过数钱时还是比较爽的~~~当今物价都在上涨,唯独工资不涨,那钱都去了哪里了呢???

  

 

出处:https://www.cnblogs.com/tong-tong/archive/2013/05/02/3049428.html

=======================================================================================

解决WebDev.Webserver4(.net 4) 只能用于本机调试的问题

 最近在弄针式PKM的支付宝在线支付,才发现VS2010自带的Asp.net Web 服务器 只能在本机访问,在网上搜索了不少资料。

1、尝试方案一:有一个一键访问的叫Aspnet4.0的没有解决这个问题,只是简单调用了自带的WebDev.WebServer40.exe 这个文件

2、找到方案二:在园子中另外找到这篇:使WebDev.WebServer.exe 当web服务器 ,很有帮助,但没有解决本机访问的调试问题,后来找到更简单的方法,支持任意IP访问,即使用 socket.Bind(new IPEndPoint(IPAddress.Any , port)); 初始服务器的监听端口(此时用netstat -a 显示 0.0.0.0 本机地址)

  2.1 用ILSpy 反编译了WebDev.WebServer40.exe 和WebDev.WebHost40.dll,修改后重新编译

  2.2 要将编译好的WebDev.WebServer40.exe 替换到:C:\Program Files\Common Files\microsoft shared\DevServer\10.0

  2.3 要将WebDev.WebHost40.dll 每次复制到要调试的asp.net 项目的bin 文件夹(没有则手工建一个)

  经以上折腾,可以在本机完成支付宝在线支付的调试。后续也可以作为简单的Asp.net Web 服务器(有安全问题,不能用于互联网)

 

3、源代码下载   https://files.cnblogs.com/fjwuyongzhi/WebDevWebServer40_fjwuyongzhi.rar

   (仅用学习参考使用)

 

【出处】:https://www.cnblogs.com/fjwuyongzhi/p/WebDevWebserver4.html

=======================================================================================

ASP.NET Web服务器:CassiniDev

使用asp.net的时候,要部署一个iis,或者部署iis express,有时候你嫌麻烦,

这是一个替代品。

功能完全的。

asp.net的处理其实是在.net framework内部的类进行处理的,这个程序调用的一样的东东,在兼容性上应该能完全保证。

至于性能,我觉得使用asp.net的人应该不会太注重性能,或者性能主要会是在数据库上。
01-cassinidev-ui.png
01-cassinidev-logviewer.png

亮点

  • Numerous bug fixes of the original Cassini source.
  • Full support for any IP address. Not limited to localhost.
    • NOTE: Due to an intentional limitation in SimpleWorkerRequest, WCF content is not servable on other than the loopback (localhost)
  • HostName support with option to temporarily add hosts file entry.
  • Port scan option. Dynamically assign an available port when specific port is not required or known to be available.
  • WaitOnPort: Length of time, in ms, to wait for specific port to become available.
  • TimeOut: Length of time, in ms, to sit idle before stopping server.
  • NTLM authentication support.
  • Single file GUI and Console applications and a library assembly for in-process hosting.
  • Painless self hosting of a full ASP.Net server implementation for applications and testing frameworks.
  • Unlike Cassini and Visual Studio Development Server, CassiniDev supports a full compliment of content types.
  • Integrated traffic monitoring.
  • Visual Studio 2008/2010 Development server drop-in replacement with all CassiniDev enhancements.


http://cassinidev.codeplex.com/

 

出处:https://www.open-open.com/lib/view/open1346821819975.html

=======================================================================================

用CassiniDev快速查看ASP.NET项目

今天下了一个

CassiniDev 3.5.1.8-4.1.0.8 release
来把自己的网站发布到网上去。
http://download.csdn.net/download/jiangtengy/3253643   在这里下了软件。打开CassiniDev4.exe  。然后把自己做的网站的文件夹路径黏贴到第一个物理路径的格子里。
在idaddress中选了any   然后就可以启动了。
在浏览器中输入  http://ip号:软件下方的端口号/login.aspx

【或下载地址:http://cassinidev.codeplex.com/releases/view/45828】

 

=============================================================

使用说明

1、准备 ASP.NET网站项目、CassiniDev软件

2、软件主界面

3、填写好参数,点击Start,其实也就填写了一个参数,即网站项目地址,所以很方便。

4、点击软件界面左下角出现的蓝色链接,就可以自动打开浏览器查看项目了。


参考:

http://blog.csdn.net/kankankankan2222/article/details/7524390

http://zhan.renren.com/programs?gid=3602888497998009817&checked=true

http://www.oschina.net/p/cassinidev

http://cassinidev.codeplex.com/downloads/get/123473

 

【出处】:https://blog.csdn.net/xiaohei5188/article/details/43985897

=======================================================================================

 个人使用

自己在网上找了一个修改好了的,可以直接开箱使用。

下载地址:webserver4.0.zip

开源地址:https://github.com/grendello/CassiniDev

posted on 2021-03-10 10:40  jack_Meng  阅读(474)  评论(1编辑  收藏  举报

导航