Making ASP.NET Development Server Listen for Remote Connections

Friday, 17 April 2009 09:51 AM
by Coose

My previous posts here and here talked about compiling Cassini and using it from Visual Studio.  After all that, I found that Cassini doesn’t understand NTLM, and writing it is complicated.  So what to do now?

Warning: I do not know about the legality of this.  This is for informational purposes only (will that hold up in a court of law?)  Additionally, make backup copies of your files before you go replacing them with your hacked versions.  You can recover the originals by reinstalling Visual Studio, but do you really want to sit through all of that?

Looking at the web server that Visual Studio uses, it consists of two parts: C:\Program Files\Common Files\microsoft shared\DevServer\9.0WebDev.WebServer.exe, and WebDev.WebHost, version=9.0.0.0, PublicKeyToken=b03f5f7f11d50a3a.  Really, the only thing I wanted to change about this program is the IPEndPont should use a IPAddress.Any instead of IPAddress.Loopback.

So the solution, let’s modify the IL, reassemble, re-sign (not resign) and reuse.

First thing to do is get the WebDev.WebHost file, make a copy (I copied to c:\temp) and disassemble.  You must copy this from a Command Prompt, as if you try to navigate here with Windows Explorer, you will start the shell extension and won’t be able to copy the file.  So:

xcopy c:\Windows\assembly\GAC_32\WebDev.WebHost\9.0.0.0__b03f5f7f11d50a3a\webdev.webhost.dll c:\temp

Now:

  1. Run ildasm
  2. Select File | Open…c:\temp\webdev.webhost.dll. 
  3. Select File | Dump, and check everything.  I saved mine to c:\temp\webdev.webhost.il

webdev1

Now, open the IL file in Visual Studio.  On line 8559, change System.Net.IPAddress::Loopback to System.Net.IPAddress::Any.

8559 IL_0020:  /* 7E   | (0A)0000A2       */ ldsfld     class [System/*23000003*/]System.Net.IPAddress/*01000035*/ [System/*23000003*/]System.Net.IPAddress/*01000035*/::LoopbackAny /* 0A0000A2 */

Do the same for the IPV6 line, line 8577:

8577 IL_004a:  /* 7E   | (0A)0000A2       */ ldsfld     class [System/*23000003*/]System.Net.IPAddress/*01000035*/ [System/*23000003*/]System.Net.IPAddress/*01000035*/::IPv6LoopbackAny /* 0A0000A2 */

And lastly, let’s change the version number, so we can be side-by-side with the “real” file in the GAC when we are finished.  Line 2078 contains the version:

2078 .ver 9:0:0:0

(change to)

2078 .ver 9:1:0:0

Now save the file and reassemble.  There are two things to remember when reassembling: don’t forget the resources, and resign with a strong key.  You will need to create a new key file using the sn.exe utility.

 

ilasm /dll /resource=webdev.webhost.res /key=c:\temp\mykey.snk webdev.webhost.il

And put it in the GAC

gacutil /i c:\temp\webdev.webhost.dll

Congratulations, you have a patched file in the GAC ready for use.  So how do we use it?  Now we have to patch WebDev.WebServer.exe.

Start the same way as above:

  1. Run ildasm
  2. File | Open…C:\Program Files\Common Files\microsoft shared\DevServer\9.0\webdev.webserver.exe
  3. File | Dump, check everything.

Now again, open the webdev.webserver.il file in Visual Studio.  There is only one thing we need to change, and that is the reference to webdev.webhost.dll.

On line 3043, update the WebDev.WebHost reference information:

3043 .assembly extern /*23000005*/ WebDev.WebHost

3044 {

3045   .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:

3046   .ver 9:0:0:0

3047 }

 

Change it to:

3043 .assembly extern /*23000005*/ WebDev.WebHost

3044 {

3045   .publickeytoken = (BA 91 52 DE BC 13 88 58 )                         // .?_....:

3046   .ver 9:1:0:0

3047 }

But the public key token will be the public key token of your signing key.  Don’t use this one…this is off of my key.  Not yours.  It’s easy to find out your public key token: Open Windows Explorer and navigate to c:\windows\assembly.  Scroll down to WebDev.WebHost version 9.1.0.0, and your public key token is listed.

Save that IL file, and let’s reassemble again.  Don’t forget the resources and strong name key:

ilasm /exe /resource=WebDev.WebServer.res /key=c:\temp\mykey.snk WebDev.WebServer.il

And boom goes the dynamite.

Run a web site or web project:

c:\temp\WebDev.WebServer.exe /port:1234 /path:c:\temp\myweb /vpath:myweb [/ntlm]

Go to a different machine, and connect your browser of choice: http://originalMachine:1234/MyWeb and revel and bask in the fact that you got everyone kissin’ your ass.

Comment on this
Development
|

Comments (10) -

Vinicius | Reply
9/2/2009 9:42:21 PM #
Fantastic job. Didn't know the ildasm power. Good to know. Go Mule!
Pelle | Reply
9/6/2009 11:39:59 PM #
Great work! This is exactly what I needed, can't believe MS didn't offer the option in the dev server.

Anyhow, patched the application and it works .. almost =) When performing requests to the loopback interface it works normally, but when performing the requests to the IP of another interface I get a HTTP 403 - Forbidden error. Obviously something is listening and trying to perform the request, so far so good (the version information on the bottom of the error page also correctly indicates ASP.NET Development Server 9.1.0.0), but then gets stuck somewhere, maybe a permission-issue. It doesn't matter whether if it is a req to an ASP.NET app or a req to a simple textfile, always HTTP 403 - Forbidden.

Any idea? I'm using Windows 7 for what its worth.

Well, guess I'll have to install the ol' IIS hog in the mean time
Ivan | Reply
10/29/2009 11:36:49 PM #
Hey Pelle, did you manage to get away with the 403 Error? I'm still trying to figure out what is the issue all about. Let me know if you have solved it. Thanks!
Ivan | Reply
10/29/2009 11:53:19 PM #
Hey Pelle,

Did you managed to get your application work? I'm getting the HTTP 403 - Forbidden error as well.
muttech | Reply
11/1/2009 5:33:50 AM #
@Pelle:
On line 2810 of webdev.webhost.il you need to change brfalse to brtrue.  This will force the RemoteIP to 127.0.0.1 which will allow the IsLocal check to evaluate as true and not return a 403.

Here's what my new version looks like:

    IL_001a:  /* 2C   | 0C               */ brtrue.s  IL_0028
Giorgio | Reply
11/13/2009 6:24:26 AM #
I solved the problem simply setting a port forwarding without touch the Visual Studio Web Server components.
If your Development Web Server is listening e.g. on http://localhost:54211, you have to set a listening on your visible ip (e.g. "192.168.0.101") on another free port (e.g. 54200) and forward the traffic to "localhost" on "54211".
I used a free tool (NetworkActiv AUTAPF 1.0) to forwarding and it works right!
Coose | Reply
11/14/2009 5:54:51 PM #
Well, that would be much easier, wouldn't it?  The thought never even crossed my mind.
Forklift Sales | Reply
1/11/2011 9:15:42 PM #
very nice blog. Ready to hear more in the future.
Cooldude | Reply
1/13/2011 2:34:00 PM #
Excellent.....Thanks for this method...Reallly interesting......
Manoj Chouhan United States | Reply
10/18/2011 11:32:11 PM #
BlackBerry is a line of wireless Smartphone handheld devices which is specifically designed for business segment. It is mostly know for its push e-mail services. Apart from that it has many other rich features like text messaging, internet faxing, web browsing and other wireless information services.


<a href="http://www.cdnmobilesolutions.com/">mobile application developers</a>

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading