有谁用过System.Web.Hosting,使aspx,asmx页面脱离IIS来运行,高手来,顶者有分

leonbingo 2006-07-31 10:49:34
现在有个项目要求做一个独立的服务器,也就是让页面脱离IIS独立运行,在MSDN上面有相应的例程,可是居然编译不过去,郁闷ing,请有相关经验的大侠来指点一下,分不够可以再家,例程里面用的是HttpListener,如果哪位有利用TcpListener来做监听的更好,分不够的话我开贴再加

MSDN上的例子:http://www.microsoft.com/china/MSDN/library/WebServices/WebServices/ServiceStation.mspx?mfr=true

几个示例代码:
http://msdn.microsoft.com/msdnmag/issues/04/12/ServiceStation/default.aspx?fig=true#fig2
...全文
508 19 打赏 收藏 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
Nov04 2006-08-14
  • 打赏
  • 举报
回复
帮你顶
terry_12 2006-08-13
  • 打赏
  • 举报
回复
mark
leonbingo 2006-08-13
  • 打赏
  • 举报
回复
谁能重写一个HttpWorkRequest对象?
C5662601 2006-08-07
  • 打赏
  • 举报
回复
学习
leonbingo 2006-08-07
  • 打赏
  • 举报
回复
public void StartListen()
{
while (true)
{
int startPos = 0;
string request = "";
string dirName = "";
string requestFile = "";
string errorMessage = "";
string localDir = "";
string rootDir = GetHostInfo(HostInfo.VitualDirectory);
Socket socket = tcpListener.AcceptSocket();
if (socket.Connected)
{
byte[] receive = new byte[1024];
socket.Receive(receive);
string buffer=Encoding.ASCII.GetString(receive);

startPos = buffer.IndexOf("HTTP", 1);
string httpVersion = buffer.Substring(startPos, 8);

request = buffer.Substring(0, startPos - 1).Replace("\\", "/");

if (request.IndexOf(".") < 0 && !request.EndsWith("/"))
{
request += "/";
}

startPos = request.LastIndexOf("/") + 1;
requestFile = request.Substring(startPos);

dirName=request.Substring(request.IndexOf("/"),request.LastIndexOf("/")-3);

if (dirName == "/")
{
localDir += rootDir;
}
else
{
dirName = dirName.Replace("/", "\\");
localDir += rootDir + dirName;
}

//Find default page
if (requestFile.Length == 0)
{
requestFile = GetDefaultPage(localDir);

//Can not find the default page
if (requestFile == "")
{
NotFindPage(ref socket, httpVersion);
}
else//Find the default page
{
HandleRequest(dirName + requestFile, httpVersion, ref socket);
}

}
else//Find the request file
{
HandleRequest(dirName+requestFile, httpVersion, ref socket);
}

}
socket.Close();
}
}

private void NotFindPage(ref Socket socket, string httpVersion)
{
string errorMessage = "<iframe src=\"res://C:\\WINDOWS\\system32\\shdoclc.dll/dnserror.htm\" width=\"100%\" height=\"100%\">";
WriteHttpHeader(httpVersion, "text/html", errorMessage.Length, "404 Not Found", ref socket);
SendToBrowser(errorMessage, ref socket);
}

private void HandleRequest(string fileName,string httpVersion, ref Socket socket)
{
string virtualDir = GetHostInfo(HostInfo.VitualDirectory);
string fileExt = GetFileExt(fileName);
string mimiType = GetMimeType(fileName);
byte[] content=null;
if (fileExt == ".aspx" || fileExt == ".asmx")
{
MyHost myHost = (MyHost)ApplicationHost.CreateApplicationHost(typeof(MyHost), "/", virtualDir);
//MyHost myHost = new MyHost();
content = Encoding.ASCII.GetBytes(myHost.HandleRequest(virtualDir + fileName));
}
else
{
if (File.Exists(virtualDir + fileName))
{
FileStream fs = new FileStream(virtualDir + fileName, FileMode.Open);
content = new byte[fs.Length];
fs.Read(content, 0, content.Length);
fs.Close();
}
else
{
NotFindPage(ref socket, httpVersion);
}

}
WriteHttpHeader(httpVersion, mimiType, content.Length, "200 OK", ref socket);
SendToBrowser(content, ref socket);
}

~HttpServer()
{
tcpListener.Stop();
}

}

public class MyHost : MarshalByRefObject
{
public string HandleRequest(string fileName)
{
StringWriter wr = new StringWriter();
HttpWorkerRequest worker = new SimpleWorkerRequest(fileName, "", wr);
HttpRuntime.ProcessRequest(worker);
return wr.ToString();
}
}
}
leonbingo 2006-08-07
  • 打赏
  • 举报
回复
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Collections;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Hosting;
using System.Xml;

namespace MyHttpServer
{
public class HttpServer:MarshalByRefObject
{
public enum HostInfo { VitualDirectory, Port }
public static TcpListener tcpListener;

public HttpServer()
{
try
{
tcpListener = new TcpListener(int.Parse(GetHostInfo(HostInfo.Port)));
tcpListener.Start();

Thread thread = new Thread(new ThreadStart(StartListen));
thread.Start();
}
catch
{

}
}

public string GetHostInfo(HostInfo Info)
{
string rValue = "";
string xPath = "";
if (Info.Equals( HostInfo.VitualDirectory))
{
xPath = "HostSetting/VirtualDir";
}
else if (Info.Equals( HostInfo.Port))
{
xPath = "HostSetting/Port";
}
else
{
return "";
}

try
{
XmlDocument xd = new XmlDocument();
xd.Load(AppDomain.CurrentDomain.BaseDirectory + "HostSetting.xml");
XmlNode xn = xd.SelectSingleNode(xPath);
rValue = xn.InnerText;
return rValue;
}
catch
{
throw;
}
}

public string GetDefaultPage(string localDirectory)
{
try
{
XmlDocument xd = new XmlDocument();
xd.Load(AppDomain.CurrentDomain.BaseDirectory + "HostSetting.xml");
string xPagePath = "HostSetting/DefaultPage";
if (!localDirectory.EndsWith("\\"))
{
localDirectory += "\\";
}

foreach (XmlNode xn in xd.SelectSingleNode(xPagePath))
{
if (File.Exists(localDirectory + xn.InnerText))
{
return "\\"+xn.InnerText;
}
}

return "";
}
catch
{
throw;
}
}

public string GetMimeType(string requestFile)
{
string mimeType = "";
string fileExt = GetFileExt(requestFile);

try
{
string xPath = "HostSetting/Mime/Values/Type[../Ext='" + fileExt + "']";
XmlDocument xd = new XmlDocument();
xd.Load(AppDomain.CurrentDomain.BaseDirectory + "HostSetting.xml");
XmlNode mimeNode = xd.SelectSingleNode(xPath);
if (mimeNode != null)
{
mimeType = mimeNode.InnerText;
return mimeType;
}
else
{
return "";
}
}
catch
{
throw;
}
}

private string GetFileExt(string requestFile)
{
string fileExt = "";

int startPos = requestFile.IndexOf(".");
int endPos = requestFile.IndexOf("?");

if (endPos != -1)
{
fileExt = requestFile.Substring(startPos, endPos - startPos);
}
else
{
fileExt = requestFile.Substring(startPos);
}
fileExt = fileExt.ToLower();
return fileExt;
}

public void WriteHttpHeader(string httpVersion, string mimeHeader, int totalBytes, string statusCode, ref Socket mySocket)
{
string buffer = "";

if (mimeHeader.Length == 0)
{
mimeHeader = "text/html";
}

buffer += httpVersion + statusCode + "\r\n";
buffer += "Server:MyServer\r\n";
buffer += "Content-Type:" + mimeHeader + "\r\n";
buffer += "Acccept-Ranges:bytes\r\n";
buffer += "Content-Length:" + totalBytes + "\r\n\r\n";

SendToBrowser(Encoding.ASCII.GetBytes(buffer),ref mySocket);
}

public void SendToBrowser(byte[] sendDate, ref Socket mySocket)
{
try
{
if (mySocket.Connected)
{
if (mySocket.Send(sendDate) == -1)
{
}
}
else
{

}
}
catch
{
throw;
}
}

public void SendToBrowser(string sendDate, ref Socket mySocket)
{
SendToBrowser(Encoding.ASCII.GetBytes(sendDate), ref mySocket);
}


Radar2006 2006-08-07
  • 打赏
  • 举报
回复
up
华尔兹 2006-08-07
  • 打赏
  • 举报
回复
帮顶顺便MARK
zlkingdom 2006-08-07
  • 打赏
  • 举报
回复
学习了~~我还没试过不用IIS运行网站
leonbingo 2006-08-07
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="utf-8" ?>
<HostSetting>
<VirtualDir>c:\temp</VirtualDir>
<Port>8001</Port>
<DefaultPage>
<File>default.htm</File>
<File>default.html</File>
<File>default.aspx</File>
<File>default.asmx</File>
</DefaultPage>
<Mime>
<Values>
<Ext>.htm</Ext>
<Type>text/html</Type>
</Values>
<Values>
<Ext>.html</Ext>
<Type>text/html</Type>
</Values>
<Values>
<Ext>.aspx</Ext>
<Type>text/html</Type>
</Values>
<Values>
<Ext>.asmx</Ext>
<Type>text/html</Type>
</Values>
<Values>
<Ext>.gif</Ext>
<Type>image/gif</Type>
</Values>
<Values>
<Ext>.jpg</Ext>
<Type>image/jpg</Type>
</Values>
</Mime>
</HostSetting>
Radar2006 2006-08-01
  • 打赏
  • 举报
回复
up
ZJguhong 2006-08-01
  • 打赏
  • 举报
回复
up
zhengjob 2006-08-01
  • 打赏
  • 举报
回复
mark
leonbingo 2006-08-01
  • 打赏
  • 举报
回复
没有人了么,faint,呵呵
Zine_Alone 2006-08-01
  • 打赏
  • 举报
回复
帮顶!
leonbingo 2006-07-31
  • 打赏
  • 举报
回复
先谢谢,希望还能有人多给点例子
fcuandy 2006-07-31
  • 打赏
  • 举报
回复
mark
siugwan 2006-07-31
  • 打赏
  • 举报
回复
mark
孟子E章 2006-07-31
  • 打赏
  • 举报
回复
完整例子和编译方法
http://radio.weblogs.com/0105476/stories/2002/10/24/executingAsmxFilesWithoutAWebServer.html
http://radio.weblogs.com/0105476/stories/2002/07/12/executingAspxPagesWithoutAWebServer.html
源码直接下载地址: https://pan.quark.cn/s/a4b39357ea24 ### 以单片机为核心的火灾报警系统毕业论文开题报告相关知识点 #### 一、课题背景及意义 ##### (1)课题背景 随着科学技术的持续进步和社会经济的高速发展,火灾现象已经成为一个日益突出的安全问题。特别是在人口高度聚集的城市区域,由于多种因素导致的火灾事故时有发生,给人员生命安全和财产带来了严重的威胁。因此,如何高效地预防火灾事故并迅速进行应对处理,成为了当前亟待解决的重要课题之一。传统的火灾监测与报警装置普遍存在响应时间较长、误报现象频繁、维护费用高昂等不足,难以适应现代社会对火灾防控的迫切需求。而采用单片机技术构建的智能火灾报警装置,凭借其反应迅速、运行可靠、成本较低等优势,正受到业界的广泛重视。 ##### (2)课题意义 以单片机为基础的火灾报警装置旨在综合运用现代电子工程技术和计算机科学方法,研发一种能够实时监控环境中的烟雾含量及温度变化,并在参数超过设定标准时迅速发出警示信号的智能化装置。此类系统不仅能够显著提升火灾预警的精确度和时效性,还能有效减少误报情况,从而为公民生命财产提供更加周全的安全保障。 #### 二、国内外研究发展情况 目前,在国内外范围内,关于智能火灾报警系统的研发工作已经取得了长足的进步。在国外,许多国家已经大规模部署了基于物联网理念的智能火灾监测系统,这些系统不仅具备基础的烟雾探测能力,还能通过无线通信网络即时将火灾数据传输至消防机构,大幅度提升了应急救援工作的效率。在国内,尽管相关技术的研究起步相对较晚,但近年来随着国家对公共安全领域的关注程度不断提高,基于单片机技术、嵌入式系统等智能火灾报警设备正经历着快速的发展阶段。 #### ...
源码下载地址: https://pan.quark.cn/s/7c5ebe7e1146 专门用于处理和播放监控系统生成的MP4视频文件的软件工具即为监控专用MP4文件播放器。此类播放器通常配备特殊功能,能够解析和播放那些因编码格式特殊或包含特定行业标准而在常规多媒体播放器上无法打开的MP4文件。作为常见类型,H264文件播放器得到了广泛应用,因为H264(也称为AVC,即Advanced Video Coding)是当前监控录像最常用的视频编码格式之一,其高效的压缩比率能在维持良好画质的条件下减小文件体积。 监控视频的编码方法通常与一般娱乐视频存在差异,可能包含更复杂的元数据或专有的加密技术,旨在保障数据的安全性和隐私性。因此,标准MP4播放器可能因无法识别这些特征而无法正常播放。针对这些特点进行优化的监控专用MP4文件播放器,则能够确保正确解码和播放相关文件。 描述中提及的"各种录像文件"可能涵盖以下几种情形: 1. 非标准分辨率:监控摄像头或许会采用非典型的分辨率,如320x240、720x480等,这些在标准播放器中可能无法得到支持。 2. 特殊帧率:监控录像或许会采用非常规的帧率,例如1fps、5fps等,这与一般视频的24fps、30fps有所不同。 3. 非线性时间轴:部分监控系统可能会进行时间戳重置,导致视频时间线呈现非线性,普通播放器可能无法正确处理。 4. 加密保护:为防止未授权的访问,监控录像可能被加密,需要特定的播放器才能进行解密。 5. 多通道音频:部分监控设备或许会包含多个音频通道,例如同时记录多路音频,普通播放器可能无法同时播放。 在提供的压缩包文件中,"下载说明.htm"或许包含了软件的安装指南、使用教程或注意事项,对于用户而言至关...
摘要 在数字经济与乡村振兴深度融合的背景下,针对果蔬产品助农销售中存在的信息不对称、销售渠道单一、管理粗放及资金监管不足等痛点,为畅通果蔬产销对接、提升助农工作的规范化与数字化水平,研究设计并实现了一款果蔬产品助农销售系统。研究采用前后端分离的B/S架构,以SpringBoot为后端核心框架、Vue.js为前端开发框架,搭配MySQL数据库搭建系统技术架构;通过技术、经济、操作三维度可行性分析与功能需求分析,划分管理员、农商、消费者三大用户角色,运用UML建模梳理业务流程,完成系统模块化设计与数据库逻辑结构搭建,最终通过黑盒测试验证系统功能有效性。系统实现了管理端、农商端、消费者端三大子系统的功能整合,涵盖农商信息管理、助农项目全生命周期管控、果蔬商城运营、助农资金闭环监管、商品销售与订单跟踪等核心功能,各模块运行稳定、数据交互准确,可有效满足果蔬助农销售的实际业务需求。该系统为果蔬产品助农销售提供了数字化解决方案,实现了助农业务的信息化管理,为农业数字化转型提供了技术支撑,同时系统在数据安全、功能维度等方面仍有优化空间,可通过后续迭代进一步提升实用性。 关键词 果蔬产品;助农销售系统;SpringBoot

111,128

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧