示例#1
0
        public static ActionResult SendHtml(this HttpListenerResponse response, HtmlResponse r)
        {
            //Buffer
            byte[] buffer = new byte[r.BufferSize];
            //Content type
            response.ContentType = "text/html";
            //Get string resource
            string content = r.Content;

            if (r.ReplaceDict != null)
            {
                foreach (string key in r.ReplaceDict.Keys)
                {
                    content = content.Replace(key, r.ReplaceDict[key]);
                }
            }
            //open output stream
            using (var net = response.OutputStream)
            {
                using (Stream st = new MemoryStream(r.Encode.GetBytes(content)))
                {
                    while (true)
                    {
                        int count = st.Read(buffer, 0, buffer.Length);
                        if (count <= 0)
                        {
                            break;
                        }
                        net.Write(buffer, 0, count);
                    }
                }
            }            //end write

            return(ActionResult.Handled);
        }
示例#2
0
		public static ActionResult SendHtml(this HttpListenerResponse response, HtmlResponse r)
		{
			//Buffer
			byte[] buffer = new byte[r.BufferSize];
			//Content type
			response.ContentType = "text/html";
			//Get string resource
			string content = r.Content;

			if (r.ReplaceDict != null)
			{
				foreach (string key in r.ReplaceDict.Keys)
				{
					content = content.Replace(key, r.ReplaceDict[key]);
				}
			}
			//open output stream
			using (var net = response.OutputStream)
			{
				using (Stream st = new MemoryStream(r.Encode.GetBytes(content)))
				{
					while (true)
					{
						int count = st.Read(buffer, 0, buffer.Length);
						if (count <= 0)
							break;
						net.Write(buffer, 0, count);
					}
				}
			}//end write

			return ActionResult.Handled;
		}