zoukankan      html  css  js  c++  java
  • WebDev.WebServer40.EXE

    http://www.cnblogs.com/tong-tong/archive/2013/05/02/3049428.html 大学玩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.Request的TryParseRequest()方法一个判断注释掉
    复制代码
    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.Connection的GetHost()方法里加入如下代码(要把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 后记
    近来在各种房贷、老婆贷的压力下接了各种私活,各种加班,各种被坑,不过数钱时还是比较爽的~~~当今物价都在上涨,唯独工资不涨,那钱都去了哪里了呢???
  • 相关阅读:
    Photoshop 基础七 位图 矢量图 栅格化
    Photoshop 基础六 图层
    Warfare And Logistics UVALive
    Walk Through the Forest UVA
    Airport Express UVA
    Guess UVALive
    Play on Words UVA
    The Necklace UVA
    Food Delivery ZOJ
    Brackets Sequence POJ
  • 原文地址:https://www.cnblogs.com/adodo1/p/4328216.html
Copyright © 2011-2022 走看看