HTTP服务器软件系统的设计与实现(20)
时间:2017-02-21 13:09 来源:毕业论文 作者:毕业论文 点击:次
public static ApplicationResponse Generate404Page(HttpRequest request, string bodyMessage, string pageHeader, string title = "Error Page") { //检查如果存在defaultPage if (!File.Exists(HttpApplicationManager.RootDirectory + "\\" + HttpApplicationManager.DefaultPage)) { //没有数据发送回来,所以连接将关闭。 return new ApplicationResponse(request) { Action = ResponseAction.Disconnect }; } //获取文件 byte[] page = Helper.GetFile(HttpApplicationManager.RootDirectory + "\\" + HttpApplicationManager.DefaultPage); string page_str = new String(Encoding.UTF8.GetChars(page)); //与异常信息填写页面 page_str = page_str.Replace("<%ws_title%>", title); page_str = page_str.Replace("<%ws_domain%>", HttpApplicationManager.CurrentDomain + ":" + HttpApplicationManager.ServicePort); page_str = page_str.Replace("<%ws_header%>", pageHeader); page_str = page_str.Replace("<%ws_message%>", bodyMessage); page = Encoding.UTF8.GetBytes(page_str); //获取pageHeader byte[] binheader = GetHeader(page.Length, MimeType.text_html, true, false); //构建响应 byte[] completeResponse = binheader.Concat(page); ApplicationResponse response = new HttpResponse(completeResponse, request); return response; } /// <summary> /// 从资源提取源MimeType /// </summary> /// <param name="request"></param> /// <returns></returns> public static MimeType GetResourceMime(string request) { if (string.IsNullOrEmpty(request)) return MimeType.none; string[] filepats = request.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); if (filepats.Length > 0) { (责任编辑:qin) |