当前位置: 首页>>代码示例>>C#>>正文


C# Web.HttpResponse类代码示例

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


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


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