需要一些帮助以继续该程序 [英] Need some help to continue the program

查看:93
本文介绍了需要一些帮助以继续该程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



以下是我创建的简单服务器.它仅打印"Welcome to message".我想在其上显示特定的aspx页面.在以下代码中需要对此进行哪些更改.

谢谢

Hi,

Following is the simple server i have created.It just printing the "Welcome to message only.I would like to display a particular aspx page on it.What changes i need to apply for that in the below coding.

Thanks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net;
using System.IO;
using System.Diagnostics;

namespace WebServer
{
    class servernew
    {
        static void Main(string[] args)
        {
            HttpListener listner = null;
            try
            {
                listner= new HttpListener();
                listner.Prefixes.Add("http://localhost:1300/");
                listner.Start();
                while(true)
                {
                 Console.WriteLine("Waiting....");
                    HttpListenerContext context =listner.GetContext();
                    string msg = "Welcome to the server"; 
                    context.Response.ContentLength64=Encoding.UTF8.GetByteCount(msg);
                    context.Response.StatusCode=(int)HttpStatusCode.OK;
                    using(Stream stream=context.Response.OutputStream)
                    {
                        using(StreamWriter writer =new StreamWriter(stream))
                        {
                            writer.Write(msg);
                            
                        }
                    }
                    Console.WriteLine("Message Sent.....");
                }
            }
            catch(WebException e)
            {
                Console.WriteLine(e.Status);
            }
        }
    }
}

推荐答案

首先,您需要将其从控制台应用程序转换为Windows Forms应用程序.可以找到许多示例
Firstly you need to convert this from a console application to a Windows Forms application. Lots of samples can be found here[^] to help you.


这篇关于需要一些帮助以继续该程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆