• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Web.HttpResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Web.HttpResponse的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse类的具体用法?C# HttpResponse怎么用?C# HttpResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HttpResponse类属于System.Web命名空间,在下文中一共展示了HttpResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ReplyError

 private void ReplyError(HttpStatusCode statusCode, string text, HttpResponse response)
 {
     response.StatusCode = (int)statusCode;
     response.ContentType = "text/html";
     response.Write(String.Format("<html><title>MovieInfo : ERROR</title><body><p>{0}</p></body></html>", text));
     for (int i = 0; i < 85; ++i) response.Write("&nbsp;");
 }
开发者ID:sandrapatfer,项目名称:PROMPT11-07-ConcurrentProgramming.sandrapatfer,代码行数:7,代码来源:MovieInfoTPL2Handler.cs


示例2: InvokeServiceHandler

        /// <summary>
        /// Invokes the appropriate service handler (registered using a ServiceAttribute)
        /// </summary>
        public void InvokeServiceHandler(Message request, Message response, HttpSessionState session, HttpResponse httpresponse)
        {
            if (request.Type.Equals(this.Request))
            {
                try
                {
                    Message temp_response = response;
                    Object[] parameters = new Object[] { request, temp_response };
                    Object declaringTypeInstance = Activator.CreateInstance(this.MethodInfo.DeclaringType);
                    this.MethodInfo.Invoke(declaringTypeInstance, parameters);
                    temp_response = (Message)parameters[1];
                    temp_response.Type = this.Response;
                    temp_response.Scope = request.Scope;
                    temp_response.Version = request.Version;
                    temp_response.RequestDetails = request.RequestDetails;

                    Logger.Instance.Debug("Invoked service for request: " + request.Type);
                    Dispatcher.Instance.EnqueueOutgoingMessage(temp_response, session.SessionID);
                }
                catch (Exception e)
                {
                    String err = "";
                    err+="Exception while invoking service handler - " + this.MethodInfo.Name + " in " + this.MethodInfo.DeclaringType.Name + "\n";
                    err += "Request Message - " + request.Type + "\n";
                    err += "Response Message - " + response.Type + "\n";
                    err += "Message - " + e.Message + "\n";
                    err += "Stacktrace - " + e.StackTrace + "\n";
                    Logger.Instance.Error(err);
                }
            }
        }
开发者ID:appcelerator,项目名称:entourage,代码行数:34,代码来源:Service.cs


示例3: Indexer

		public void Indexer ()
		{
			HttpResponse response = new HttpResponse (Console.Out);
			HttpCacheVaryByContentEncodings encs = response.Cache.VaryByContentEncodings;

			encs ["gzip"] = true;
			encs ["bzip2"] = false;

			Assert.IsTrue (encs ["gzip"], "gzip == true");
			Assert.IsFalse (encs ["bzip2"], "bzip2 == false");

			bool exceptionCaught = false;
			try {
				encs [null] = true;
			} catch (ArgumentNullException) {
				exceptionCaught = true;
			}
			Assert.IsTrue (exceptionCaught, "ArgumentNullException on this [null] setter");

			exceptionCaught = false;
			try {
				bool t = encs [null];
			} catch (ArgumentNullException) {
				exceptionCaught = true;
			}
			Assert.IsTrue (exceptionCaught, "ArgumentNullException on this [null] getter");
		}
开发者ID:nobled,项目名称:mono,代码行数:27,代码来源:HttpCacheVaryByContentEncodingsTest.cs


示例4: GetRouteData

        /// <summary>
        /// Parses specified url and returns a RouteData instance. 
        /// Then, for example, you can do: routeData.Values["controller"]
        /// </summary>
        public static RouteData GetRouteData(this RouteCollection routeCollection, string url, string queryString = null)
		{
            var request = new HttpRequest(null, url, queryString);
            var response = new HttpResponse(new StringWriter());
            var httpContext = new HttpContext(request, response);
            return RouteTable.Routes.GetRouteData(new HttpContextWrapper(httpContext));
		}
开发者ID:matutee,项目名称:Bardock.Utils,代码行数:11,代码来源:RouteCollectionExtensions.cs


示例5: SendNotFoundResponse

 private static void SendNotFoundResponse(string message, HttpResponse httpResponse)
 {
     httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
     httpResponse.ContentType = "text/plain";
     httpResponse.Write(message);
     httpResponse.End(); // This terminates the HTTP processing pipeline
 }
开发者ID:sdl,项目名称:dxa-modules,代码行数:7,代码来源:AzureUnknownLocalizationHandler.cs


示例6: Serialize

        /// <summary> Serialize the return object, according to the protocol requested </summary>
        /// <param name="ReturnValue"> Return object to serialize </param>
        /// <param name="Response"> HTTP Response to write result to </param>
        /// <param name="Protocol"> Requested protocol type </param>
        /// <param name="CallbackJsonP"> Callback function for JSON-P </param>
        protected void Serialize(object ReturnValue, HttpResponse Response, Microservice_Endpoint_Protocol_Enum Protocol, string CallbackJsonP)
        {
            if (ReturnValue == null)
                return;

            switch (Protocol)
            {
                case Microservice_Endpoint_Protocol_Enum.JSON:
                    JSON.Serialize(ReturnValue, Response.Output, Options.ISO8601ExcludeNulls);
                    break;

                case Microservice_Endpoint_Protocol_Enum.PROTOBUF:
                    Serializer.Serialize(Response.OutputStream, ReturnValue);
                    break;

                case Microservice_Endpoint_Protocol_Enum.JSON_P:
                    Response.Output.Write(CallbackJsonP + "(");
                    JSON.Serialize(ReturnValue, Response.Output, Options.ISO8601ExcludeNullsJSONP);
                    Response.Output.Write(");");
                    break;

                case Microservice_Endpoint_Protocol_Enum.XML:
                    XmlSerializer x = new XmlSerializer(ReturnValue.GetType());
                    x.Serialize(Response.Output, ReturnValue);
                    break;

                case Microservice_Endpoint_Protocol_Enum.BINARY:
                    IFormatter binary = new BinaryFormatter();
                    binary.Serialize(Response.OutputStream, ReturnValue);
                    break;
            }
        }
开发者ID:Elkolt,项目名称:SobekCM-Web-Application,代码行数:37,代码来源:EndpointBase.cs


示例7: DeleteCookie

 public static void DeleteCookie(HttpRequest Request, HttpResponse Response, string name, string value)
 {
     HttpCookie cookie = new HttpCookie(name);
     cookie.Expires = DateTime.Now.AddDays(-1D);
     cookie.Value = value;
     Response.AppendCookie(cookie);
 }
开发者ID:the404,项目名称:xyz,代码行数:7,代码来源:CookieHelper.cs


示例8: FakeHttpContext

        public static HttpContext FakeHttpContext()
        {
            using (var stringWriter = new StringWriter())
            {
                var httpRequest = new HttpRequest("", "http://abc", "");

                var httpResponse = new HttpResponse(stringWriter);
                var httpContext = new HttpContext(httpRequest, httpResponse);

                var sessionContainer = new HttpSessionStateContainer(
                    "id",
                    new SessionStateItemCollection(), 
                    new HttpStaticObjectsCollection(),
                    10,
                    true,
                    HttpCookieMode.AutoDetect,
                    SessionStateMode.InProc,
                    false);

                httpContext.Items["AspSession"] = typeof(HttpSessionState).GetConstructor(
                    BindingFlags.NonPublic | BindingFlags.Instance,
                    null,
                    CallingConventions.Standard,
                    new[] {typeof(HttpSessionStateContainer)},
                    null)
                    .Invoke(new object[] {sessionContainer});

                return httpContext;
            }
        }
开发者ID:TomJerrum,项目名称:FinalYearProjectBlog,代码行数:30,代码来源:HttpContextFaker.cs


示例9: ExportToExcel

        public void ExportToExcel(DataTable dataTable, HttpResponse response)
        {
            // Create a dummy GridView
            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.DataSource = dataTable;
            GridView1.DataBind();
            response.Clear();
            response.Buffer = true;
            response.AddHeader("content-disposition", "attachment;filename=DataTable.xls");
            response.Charset = "";
            response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            for (int i = 0; (i
                        <= (GridView1.Rows.Count - 1)); i++)
            {
                // Apply text style to each Row
                GridView1.Rows[i].Attributes.Add("class", "textmode");
            }

            GridView1.RenderControl(hw);
            // style to format numbers to string
            string style = "<style> .textmode{mso-number-format:\\@;}</style>";
            response.Write(style);
            response.Output.Write(sw.ToString());
            response.Flush();
            response.End();
        }
开发者ID:rudolfcruz,项目名称:Reports,代码行数:29,代码来源:GenReportes.cs


示例10: ExportToCSV

        public void ExportToCSV(DataTable dataTable, HttpResponse response)
        {
            response.Clear();
            response.Buffer = true;
            response.AddHeader("content-disposition",
                "attachment;filename=DataTable.csv");
            response.Charset = "";
            response.ContentType = "application/text";

            StringBuilder sb = new StringBuilder();
            for (int k = 0; k < dataTable.Columns.Count; k++)
            {
                //add separator
                sb.Append(dataTable.Columns[k].ColumnName + ',');
            }
            //append new line
            sb.Append("\r\n");
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                for (int k = 0; k < dataTable.Columns.Count; k++)
                {
                    //add separator
                    sb.Append(dataTable.Rows[i][k].ToString().Replace(",", ";") + ',');
                }
                //append new line
                sb.Append("\r\n");
            }
            response.Output.Write(sb.ToString());
            response.Flush();
            response.End();
        }
开发者ID:rudolfcruz,项目名称:Reports,代码行数:31,代码来源:GenReportes.cs


示例11: Real

        private void Real(HttpResponse response, HttpRequest request)
        {
            if (File.Exists(request.PhysicalPath))
            {
                FileInfo file = new System.IO.FileInfo(request.PhysicalPath);
                response.Clear();
                response.AddHeader("Content-Disposition", "filename=" + file.Name);
                response.AddHeader("Content-Length", file.Length.ToString());
                string fileExtension = file.Extension.ToLower();
                switch (fileExtension)
                {
                    case ".mp3":
                        response.ContentType = "audio/mpeg3";
                        break;
                    case ".mpeg":
                        response.ContentType = "video/mpeg";
                        break;
                    case ".jpg":
                        response.ContentType = "image/jpeg";
                        break;
                    case ".bmp":
                        response.ContentType = "image/bmp";
                        break;
                    case ".gif":
                        response.ContentType = "image/gif";
                        break;
                    case ".doc":
                        response.ContentType = "application/msword";
                        break;
                    case ".css":
                        response.ContentType = "text/css";
                        break;
                    case ".html":
                        response.ContentType = "text/html";
                        break;
                    case ".htm":
                        response.ContentType = "text/html";
                        break;
                    case ".swf":
                        response.ContentType = "application/x-shockwave-flash";
                        break;
                    case ".exe":
                        response.ContentType = "application/octet-stream";
                        break;
                    case ".inf":
                        response.ContentType = "application/x-texinfo";
                        break;
                    default:
                        response.ContentType = "application/octet-stream";
                        break;
                }

                response.WriteFile(file.FullName);
                response.End();
            }
            else
            {
                response.Write("File Not Exists");
            }
        }
开发者ID:Xiaoyuyexi,项目名称:LMS,代码行数:60,代码来源:HttpNotFound.cs


示例12: GoogleOIDC

        public GoogleOIDC(HttpRequest request, HttpResponse response)
        {
            this.request = request;
            this.response = response;

            this.accessCode = request["code"];
        }
开发者ID:pepipe,项目名称:ISEL,代码行数:7,代码来源:GoogleOIDC.cs


示例13: MakePageExpired

 //public static void DisableMasterPageStamp(Page page)
 //{
 //    Validate.NotNull(page, "page");
 //    if (page.Master != null)
 //    {
 //        Control ctrl = page.Master.FindControl(DoubleSubmitStamp.MasterPageControlName);
 //        if (ctrl != null)
 //            ((DoubleSubmitStamp) ctrl).RenderStamp = false;
 //    }
 //}
 public static void MakePageExpired(HttpResponse response)
 {
     Validate.NotNull(response, "response");
     response.Expires = 0;
     response.Cache.SetNoStore();
     response.AppendHeader("Pragma", "no-cache");
 }
开发者ID:andreyu,项目名称:Reports,代码行数:17,代码来源:WebUtils.cs


示例14: RouteContext

		/// <summary>
		/// Creates a new RouteContext
		/// </summary>
		/// <param name="request">The request.</param>
		/// <param name="response">The response.</param>
		/// <param name="applicationPath">The application path.</param>
		/// <param name="contextItems">The context items.</param>
		public RouteContext(IRequest request, HttpResponse response, string applicationPath, IDictionary contextItems)
		{
			this.request = request;
			this.response = response;
			this.applicationPath = applicationPath;
			this.contextItems = contextItems;
		}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:14,代码来源:RouteContext.cs


示例15: WriteError

 private static void WriteError(string error, HttpResponse response)
 {
     response.Clear();
     response.Status = "Internal Server Error";
     response.StatusCode = 500;
     response.Output.WriteLine(error);
 }
开发者ID:KostovMartin,项目名称:mKWays,代码行数:7,代码来源:AjaxHandler.cs


示例16: Save

        public void Save(string ipAddress, HttpContext context, HttpRequest request, HttpResponse response)
        {
            ELSLog esLog = new ELSLog();
            esLog.ElsIpaddress = ipAddress;
            /*  var x = request.Path;

              x = Getapifunction(x);

              switch (request.HttpMethod)
              {
                  case "GET" :
                      x = "SEE " + x;
                      break;
                  case "POST":
                      x = "SENT " + x;
                      break;
              }*/
            // if (x == "/api/contact")
            // {
            //     x = "sendqueue";}
            esLog.ElsRequest = "[" + DateTime.Now.ToString("dd/MMM/yyyy:HH:mm:ss zz") + "]" + " \"" + request.HttpMethod + " "
                + request.Path + "\" " + response.StatusCode + " " + request.TotalBytes + " \"" + request.UrlReferrer + "\" " + "\"" + request.UserAgent + "\"" + " " + request.Form;

            /*    if (HttpContext.Current.Session != null)
                {
                   // context.Session[Userlog] = esLog;
                    Session[Userlog] = esLog;
                }*/
            context.Items[Userlog] = esLog;
        }
开发者ID:tzkwizard,项目名称:ELS,代码行数:30,代码来源:TestLogHandler.cs


示例17: SetupFakeHttpContext

 protected HttpContext SetupFakeHttpContext()
 {
     var httpRequest = SetUpHttpRequest();
     var stringWriter = new StringWriter();
     var httpResponse = new HttpResponse(stringWriter);
     return new HttpContext(httpRequest, httpResponse);
 }
开发者ID:petemounce,项目名称:NLog.Web,代码行数:7,代码来源:TestInvolvingAspNetHttpContext.cs


示例18: ResponseAdapter

		/// <summary>
		/// Initializes a new instance of the <see cref="ResponseAdapter"/> class.
		/// </summary>
		/// <param name="response">The response.</param>
		/// <param name="currentUrl">The current URL.</param>
		/// <param name="urlBuilder">The URL builder.</param>
		/// <param name="serverUtility">The server utility.</param>
		/// <param name="routeMatch">The route match.</param>
		/// <param name="referrer">The referrer.</param>
		public ResponseAdapter(HttpResponse response, UrlInfo currentUrl, 
			IUrlBuilder urlBuilder, IServerUtility serverUtility,
			RouteMatch routeMatch, string referrer)
			: base(currentUrl, urlBuilder, serverUtility, routeMatch, referrer)
		{
			this.response = response;
		}
开发者ID:smoothdeveloper,项目名称:Castle.MonoRail,代码行数:16,代码来源:ResponseAdapter.cs


示例19: DoPost

 private void DoPost(HttpRequest httpRequest, HttpResponse httpResponse)
 {
     Dictionary<string, Stream> files = httpRequest.Files.AllKeys.ToDictionary(n => n, n => httpRequest.Files[n].InputStream);
     DirectRequest[] requests = new DirectRequestsBuilder().Build(new StreamReader(httpRequest.InputStream, httpRequest.ContentEncoding), httpRequest.Form, files);
     var responses = new DirectResponse[requests.Length];
     for(int i = 0; i < requests.Length; i++)
     {
         responses[i] = new DirectHandler(_objectFactory, _metadata).Handle(requests[i]);
     }
     using(var textWriter = new StreamWriter(httpResponse.OutputStream, httpResponse.ContentEncoding))
     {
         if(requests[0].Upload)
         {
             httpResponse.ContentType = "text/html";
             textWriter.Write("<html><body><textarea>");
             SerializeResponse(responses, textWriter);
             textWriter.Write("</textarea></body></html>");
         }
         else
         {
             httpResponse.ContentType = "application/json";
             SerializeResponse(responses, textWriter);
         }
     }
 }
开发者ID:oyvindkinsey,项目名称:extdirecthandler,代码行数:25,代码来源:DirectHttpHandler.cs


示例20: Do302Redirect

 public static void Do302Redirect(HttpResponse response, string targetURL)
 {
     response.StatusCode = 0x12e;
     response.StatusDescription = "302 Moved Permanently";
     response.RedirectLocation = targetURL;
     response.End();
 }
开发者ID:NTTDATA,项目名称:Redirector,代码行数:7,代码来源:RedirectUtils.cs



注:本文中的System.Web.HttpResponse类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Web.HttpResponseBase类代码示例发布时间:2022-05-26
下一篇:
C# Web.HttpRequestBase类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap