Home All Groups Group Topic Archive Search About

How to create a local server (i.e., localhost)

Author
2 Aug 2006 1:32 AM
ljlevend2
Is there any way to create a local server during runtime?  For example, if
you add an existing Web Site to a Solution from within Visual Studio (by
right clicking the solution in the Solution Explorer, then selecting Add -
Existing Web Site...), then Visual Studio will create an ASP.NET Development
Server on a random port (e.g., http://localhost:1619/Test).  Can a similar
thing be done during runtime with VB.NET?  If not, is it possible to have a
folder act as a permanent local server?

Note that I am using VS.NET 2005 and WinXP Pro.

Thanks for any help!
Lance

Author
2 Aug 2006 5:32 AM
Steven Cheng[MSFT]
Hello Lance,

As for the  "create a local server during runtime" question you mentioned,
do you mean you want programmtically start a local test webserver to run an
ASP.NET 2.0 web appliation from a specified file system path(directory)?

Based on my understanding, the Visual Studio 2005 use the
"WebDev.TestServer.exe" application(installed with .net framework 2.0) in
the framework directory (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727). 
When Visual Studio load and host a ASP.NET 2.0 web project in IDE, it
actually start this "WebDev.TestServer.exe" program and define the
application settings (such as physical directory path, virtual path , port
....) through commandline arguments.  For example:

the following command (suppose the current directory is the .net 2.0
framework directory) will start an ASP.NET 2.0 web project hosted in the
local webserver, the application's physical directory is at
"d:\workspace\webprojects\WebApp1",  the web app will be hosted as the
"/WebApp/" virtual path, and listening on local port 8080:

WebDev.WebServer  /port:8080  /path:"d:\workspace\webprojects\WebApp1"  
/vpath:"/WebApp1"

So we can visit the application's pages through the following local address

http://localhost:8080/WebApp1/xxx.aspx


Here is a good blog article describing the usage of the test webserver:

http://weblogs.asp.net/scottgu/archive/2005/11/21/431138.aspx

In addition, if you want to programmatically start such a web application
in the test webserver, you can consider dynamically create a process
pointing to the "WebDev.WebServer.exe" program and supply the paramters.
For example, here is a test .net code fragment that start a local webserver
session in a console application:

==================================
class Program
    {
        static void Main(string[] args)
        {
            Run();
        }

        static void Run()
        {
            Process proc = new Process();


            proc.StartInfo.FileName = HttpRuntime.ClrInstallDirectory +
"\\WebDev.WebServer.exe";

            proc.StartInfo.Arguments = " /port:8888
/path:\"D:\\temp\\precompiled\\testsite1\\updatable\"
/vpath:\"/testsite1\"";

            proc.StartInfo.CreateNoWindow = true;
            proc.StartInfo.UseShellExecute = false;

            if(proc.Start())
            {
                Console.WriteLine("local webserver started........");
            }else{
                Console.WriteLine("local webserver failed to
start........");
            }

        }
    }
========================================

BTW, since the "webdev.webserver.exe" is a winform application, I would
suggest you not try programmtically launch it in any non-interactive
service(such as ASP.NET application or windows service), because in such
service application, we can not interactively manage the created
"WebDev.WebServer" application and may cause problem.  

Hope this helps you.  If you have anything unclear above, please feel free
to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



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

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take approximately
2 business days

as the support professional working with you may need further investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscriptions/support/default.aspx.

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



This posting is provided "AS IS" with no warranties, and confers no rights.
Author
2 Aug 2006 4:09 PM
ljlevend2
Hi Steven,

Thank you so much for your excellent reply.  Your sample code was exactly
what I was looking for and was tremendously helpful.  If possible, I'm hoping
that you can help me with a few follow-up questions:

1. Is there any way to hide the icon that appears in the notification area
of the task bar?
2. Is there any way to programically stop the ASP.NET Development Server on
a given port (e.g., 8888)?
3. Is there any way to determine whether the ASP.NET Development Server is
already running on a given port?

Thanks again!
Lance


Show quoteHide quote
"Steven Cheng[MSFT]" wrote:

> Hello Lance,
>
> As for the  "create a local server during runtime" question you mentioned,
> do you mean you want programmtically start a local test webserver to run an
> ASP.NET 2.0 web appliation from a specified file system path(directory)?
>
> Based on my understanding, the Visual Studio 2005 use the
> "WebDev.TestServer.exe" application(installed with .net framework 2.0) in
> the framework directory (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727). 
> When Visual Studio load and host a ASP.NET 2.0 web project in IDE, it
> actually start this "WebDev.TestServer.exe" program and define the
> application settings (such as physical directory path, virtual path , port
> ....) through commandline arguments.  For example:
>
> the following command (suppose the current directory is the .net 2.0
> framework directory) will start an ASP.NET 2.0 web project hosted in the
> local webserver, the application's physical directory is at
> "d:\workspace\webprojects\WebApp1",  the web app will be hosted as the
> "/WebApp/" virtual path, and listening on local port 8080:
>
> WebDev.WebServer  /port:8080  /path:"d:\workspace\webprojects\WebApp1"  
> /vpath:"/WebApp1"
>
> So we can visit the application's pages through the following local address
>
> http://localhost:8080/WebApp1/xxx.aspx
>
>
> Here is a good blog article describing the usage of the test webserver:
>
> http://weblogs.asp.net/scottgu/archive/2005/11/21/431138.aspx
>
> In addition, if you want to programmatically start such a web application
> in the test webserver, you can consider dynamically create a process
> pointing to the "WebDev.WebServer.exe" program and supply the paramters.
> For example, here is a test .net code fragment that start a local webserver
> session in a console application:
>
> ==================================
> class Program
>     {
>         static void Main(string[] args)
>         {
>             Run();
>         }
>
>         static void Run()
>         {
>             Process proc = new Process();
>
>
>             proc.StartInfo.FileName = HttpRuntime.ClrInstallDirectory +
> "\\WebDev.WebServer.exe";
>
>             proc.StartInfo.Arguments = " /port:8888
> /path:\"D:\\temp\\precompiled\\testsite1\\updatable\"
> /vpath:\"/testsite1\"";
>          
>             proc.StartInfo.CreateNoWindow = true;
>             proc.StartInfo.UseShellExecute = false;
>
>             if(proc.Start())
>             {
>                 Console.WriteLine("local webserver started........");
>             }else{
>                 Console.WriteLine("local webserver failed to
> start........");
>             }
>
>         }
>     }
> ========================================
>
> BTW, since the "webdev.webserver.exe" is a winform application, I would
> suggest you not try programmtically launch it in any non-interactive
> service(such as ASP.NET application or windows service), because in such
> service application, we can not interactively manage the created
> "WebDev.WebServer" application and may cause problem.  
>
> Hope this helps you.  If you have anything unclear above, please feel free
> to post here.
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>

>
> ==================================================
>
> Get notification to my posts through email? Please refer to
>
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
>

>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial
>
> response from the community or a Microsoft Support Engineer within 1
> business day is
>
> acceptable. Please note that each follow up response may take approximately
> 2 business days
>
> as the support professional working with you may need further investigation
> to reach the
>
> most efficient resolution. The offering is not appropriate for situations
> that require
>
> urgent, real-time or phone-based interactions or complex project analysis
> and dump analysis
>
> issues. Issues of this nature are best handled working with a dedicated
> Microsoft Support
>
> Engineer by contacting Microsoft Customer Support Services (CSS) at
>
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
>
> ==================================================
>

>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
Author
3 Aug 2006 6:33 AM
Steven Cheng[MSFT]
Hi Lance,

Thanks for your reply.

As I mentioned in the last reply, the WebDev.TestServer is designed as a
GUI/winform application which is recommended to host in an interactive
logon user session and hard to automate in a non-interactive service
session. For the new questions you mentioned, here are some of my
understanding and suggestions:

1. Is there any way to hide the icon that appears in the notification area
of the task bar?
=======================
I'm afraid this is limited by the webserver.exe since by default the
windows is not displayed and it is only the icon on taskbar that let the
user to interactive with the Webserver program. And I've lookup the
disassembly code of the webserver.exe, the icon is forced to display and
there is no configuration options.


2. Is there any way to programically stop the ASP.NET Development Server on
a given port (e.g., 8888)?
======================
Since the webserver.exe is a winform application which has a main window,
when we manage it interactively, we could stop it by clicking the "Stop"
button on the winform. If you want to programmatically stop it, so far what
I've got is using WIN32 API to programmatically find the webserver.exe
application's main window and send some messages to the "Stop" button to
end it.  This also require we're doing this in an interactive environment
(in a console or winform application that running under interactive logon
session).


3. Is there any way to determine whether the ASP.NET Development Server is
already running on a given port?
========================
I think this is possible, since the port number is always append in the
webserver.exe applicaion main windows's  Caption, we can capture the
caption of the window and pick the port number from the caption string. Of
course, we need to programmatically find all the existing webserver
application windows first. 

For your convenience, I've created a complete demo project which contains
the necessary code to do the work for #2 and #3 above. Most of them require
calling win32 API through PINVOKE.  I've attached this project in this
thread, you can get it if you're using Outlook Express to visit the NNTP
newsgroup.  If you have problems accessing it, please feel free to let me
know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
Author
8 Aug 2006 3:12 AM
ljlevend2
Hi Steven,

Thank you so much for looking into my additional questions.  Your help has
been exceptional and I am very grateful.

I would be interested to review the demo project that you created but I do
not see any way to access it (I am using IE to view the Newsgroup).  You
recently sent me an email informing me of your reply.  If it wouldn't be too
much trouble, could you please send the demo project as an email attachment
to that same address (or let me know some other way to get the demo)?

Thanks again!
Lance



Show quoteHide quote
"Steven Cheng[MSFT]" wrote:

> Hi Lance,
>
> Thanks for your reply.
>
> As I mentioned in the last reply, the WebDev.TestServer is designed as a
> GUI/winform application which is recommended to host in an interactive
> logon user session and hard to automate in a non-interactive service
> session. For the new questions you mentioned, here are some of my
> understanding and suggestions:
>
> 1. Is there any way to hide the icon that appears in the notification area
> of the task bar?
> =======================
> I'm afraid this is limited by the webserver.exe since by default the
> windows is not displayed and it is only the icon on taskbar that let the
> user to interactive with the Webserver program. And I've lookup the
> disassembly code of the webserver.exe, the icon is forced to display and
> there is no configuration options.
>
>
> 2. Is there any way to programically stop the ASP.NET Development Server on
> a given port (e.g., 8888)?
> ======================
> Since the webserver.exe is a winform application which has a main window,
> when we manage it interactively, we could stop it by clicking the "Stop"
> button on the winform. If you want to programmatically stop it, so far what
> I've got is using WIN32 API to programmatically find the webserver.exe
> application's main window and send some messages to the "Stop" button to
> end it.  This also require we're doing this in an interactive environment
> (in a console or winform application that running under interactive logon
> session).
>
>
> 3. Is there any way to determine whether the ASP.NET Development Server is
> already running on a given port?
> ========================
> I think this is possible, since the port number is always append in the
> webserver.exe applicaion main windows's  Caption, we can capture the
> caption of the window and pick the port number from the caption string. Of
> course, we need to programmatically find all the existing webserver
> application windows first. 
>
> For your convenience, I've created a complete demo project which contains
> the necessary code to do the work for #2 and #3 above. Most of them require
> calling win32 API through PINVOKE.  I've attached this project in this
> thread, you can get it if you're using Outlook Express to visit the NNTP
> newsgroup.  If you have problems accessing it, please feel free to let me
> know.
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
> This posting is provided "AS IS" with no warranties, and confers no rights
Author
8 Aug 2006 5:43 AM
Steven Cheng[MSFT]
Hi Lance,

Glad to hear from you. Sure, I will send you the demo project through
email(the one I send the notify mail). Please let me know if you still have
problems getting it.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Author
9 Aug 2006 1:17 AM
ljlevend2
Got it and it works great.  Thanks again for the amazing help!

Lance