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


C# HttpException.GetHtmlErrorMessage方法代码示例

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


在下文中一共展示了HttpException.GetHtmlErrorMessage方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnAuthorizeRequest

		void OnAuthorizeRequest (object sender, EventArgs args)
		{
			HttpApplication app = (HttpApplication) sender;
			HttpContext context = app.Context;
			if (context.SkipAuthorization)
				return;

			AuthorizationConfig config = (AuthorizationConfig) context.GetConfig ("system.web/authorization");
			if (config == null)
				return;

			if (!config.IsValidUser (context.User, context.Request.HttpMethod)) {
				HttpException e =  new HttpException (401, "Unauthorized");
				
				context.Response.StatusCode = 401;
				context.Response.Write (e.GetHtmlErrorMessage ());
				app.CompleteRequest ();
			}
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:19,代码来源:UrlAuthorizationModule.cs

示例2: ProcessRequest

		public void ProcessRequest ()
		{
			string error = null;
			inUnhandledException = false;
			
			try {
				AssertFileAccessible ();
				HttpRuntime.ProcessRequest (this);
			} catch (HttpException ex) {
				inUnhandledException = true;
				error = ex.GetHtmlErrorMessage ();
			} catch (Exception ex) {
				inUnhandledException = true;
				var hex = new HttpException (400, "Bad request", ex);
				error = hex.GetHtmlErrorMessage ();
			}

			if (!inUnhandledException)
				return;
			
			if (error.Length == 0)
				error = String.Format (DEFAULT_EXCEPTION_HTML, "Unknown error");

			try {
				SendStatus (400, "Bad request");
				SendUnknownResponseHeader ("Connection", "close");
				SendUnknownResponseHeader ("Date", DateTime.Now.ToUniversalTime ().ToString ("r"));
				
				Encoding enc = Encoding.UTF8;
				
				byte[] bytes = enc.GetBytes (error);
				
				SendUnknownResponseHeader ("Content-Type", "text/html; charset=" + enc.WebName);
				SendUnknownResponseHeader ("Content-Length", bytes.Length.ToString ());
				SendResponseFromMemory (bytes, bytes.Length);
				FlushResponse (true);
			} catch (Exception ex) { // should "never" happen
				Logger.Write (LogLevel.Error, "Error while processing a request: ");
				Logger.Write (ex);
				throw;
			}
		}
开发者ID:louislatreille,项目名称:xsp,代码行数:42,代码来源:MonoWorkerRequest.cs

示例3: TryGetHtmlErrorMessage

        private static string TryGetHtmlErrorMessage(HttpException e)
        {
            Debug.Assert(e != null);

            try
            {
                return e.GetHtmlErrorMessage();
            }
            catch (SecurityException se)
            {
                // In partial trust environments, HttpException.GetHtmlErrorMessage()
                // has been known to throw:
                // System.Security.SecurityException: Request for the
                // permission of type 'System.Web.AspNetHostingPermission' failed.
                //
                // See issue #179 for more background:
                // http://code.google.com/p/elmah/issues/detail?id=179

                Trace.WriteLine(se);
                return null;
            }
        }
开发者ID:clearwavebuild,项目名称:elmah,代码行数:22,代码来源:Error.cs

示例4: LogHttpException

        private static void LogHttpException(HttpException ex, HttpContext context, RouteData routeData, BaseController controller)
        {
            int httpCode = ex.GetHttpCode();
            string message = string.Empty;
            if (httpCode == 404)
            {
                LogFileNotFound(ex, context, routeData, controller);
                return;
            }
            if ((httpCode == 400) && (routeData != null))
            {
                //if 400 came from a controller, handle it in the bad request log, not system (error) log
                LogBadRequest(ex, context, routeData, controller);
                return;
            }

            message = "Http Exception " + httpCode + " " + ex.GetHtmlErrorMessage()
                + "  \n-Message: " + ex.Message
                + "  \n-Source: " + ex.Source
                + "  \n-WebEventCode: " + ex.WebEventCode
                + "  \n-ErrorCode: " + ex.ErrorCode
                + "  \n-TargetSiteName: " + ex.TargetSite.Name
                + "  \n-StackTrace: " + ex.StackTrace;

            LogException(message, ex, Models.SystemEventLevel.Error, context, routeData, controller);
        }
开发者ID:berlstone,项目名称:GStore,代码行数:26,代码来源:ExceptionHandler.cs

示例5: Constructor2b_Deny_Unrestricted

		public void Constructor2b_Deny_Unrestricted ()
		{
			HttpException e = new HttpException ("message", new Exception ());
			e.GetHtmlErrorMessage (); // null for ms, non-null for mono
			Assert.AreEqual (500, e.GetHttpCode (), "HttpCode");
		}
开发者ID:nobled,项目名称:mono,代码行数:6,代码来源:HttpExceptionCas.cs

示例6: ProcessRequest

		/// <summary>
		///    Processes the request contained in the current instance.
		/// </summary>
		public void ProcessRequest ()
		{
			string error = null;
			inUnhandledException = false;
			
			try {
				HttpRuntime.ProcessRequest (this);
			} catch (HttpException ex) {
				inUnhandledException = true;
				error = ex.GetHtmlErrorMessage ();
			} catch (Exception ex) {
				inUnhandledException = true;
				HttpException hex = new HttpException (400, "Bad request", ex);
				if (hex != null) // just a precaution
					error = hex.GetHtmlErrorMessage ();
				else
					error = String.Format (defaultExceptionHtml, ex.Message);
			}

			if (!inUnhandledException)
				return;
			
			if (error.Length == 0)
				error = String.Format (defaultExceptionHtml, "Unknown error");

			try {
				SendStatus (400, "Bad request");
				SendUnknownResponseHeader ("Connection", "close");
				SendUnknownResponseHeader ("Date", DateTime.Now.ToUniversalTime ().ToString ("r"));
				
				Encoding enc = Encoding.UTF8;
				if (enc == null)
					enc = Encoding.ASCII;
				
				byte[] bytes = enc.GetBytes (error);
				
				SendUnknownResponseHeader ("Content-Type", "text/html; charset=" + enc.WebName);
				SendUnknownResponseHeader ("Content-Length", bytes.Length.ToString ());
				SendResponseFromMemory (bytes, bytes.Length);
				FlushResponse (true);
			} catch (Exception ex) { // should "never" happen
				throw ex;
			}
		}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:47,代码来源:MonoWorkerRequest.cs

示例7: FinishWithException

		static void FinishWithException (HttpWorkerRequest wr, HttpException e)
		{
			int code = e.GetHttpCode ();
			wr.SendStatus (code, HttpWorkerRequest.GetStatusDescription (code));
			wr.SendUnknownResponseHeader ("Connection", "close");
			Encoding enc = Encoding.ASCII;
			wr.SendUnknownResponseHeader ("Content-Type", "text/html; charset=" + enc.WebName);
			string msg = e.GetHtmlErrorMessage ();
			byte [] contentBytes = enc.GetBytes (msg);
			wr.SendUnknownResponseHeader ("Content-Length", contentBytes.Length.ToString ());
			wr.SendResponseFromMemory (contentBytes, contentBytes.Length);
			wr.FlushResponse (true);
			wr.CloseConnection ();
			HttpApplication.requests_total_counter.Increment ();
		}
开发者ID:Profit0004,项目名称:mono,代码行数:15,代码来源:HttpRuntime.cs

示例8: WriteUnauthorizedResponseHtml

        protected virtual void WriteUnauthorizedResponseHtml(HttpContext context)
        {
            //
            // Let's try to get the ASP.NET runtime to give us the HTML for a
            // security exception. If we can't get this, then we'll write out
            // our own default message. A derived implementation may want to
            // also want to involve custom error messages for production
            // scenarios, which is not done here.
            //

            HttpException error = new HttpException(401, null, new SecurityException());
            string html = Mask.NullString(error.GetHtmlErrorMessage());

            if (html.Length == 0)
                html = DefaultUnauthorizedResponseHtml;

            context.Response.Write(html);
        }
开发者ID:JBetser,项目名称:Imagenius_SDK,代码行数:18,代码来源:FormsAuthenticationDispositionModule.cs

示例9: AddHttpExceptionData

        /// <summary>
        /// Add Exception data to the object fields
        /// </summary>
        /// <param name="errorcoderule">The error code rule.</param>
        /// <param name="context">An HttpContext object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        /// <param name="httpException">an HTTP exception thrown</param>
        /// <param name="rules">WebErrorCode rule from dictionary</param>
        private void AddHttpExceptionData(VLogErrorCode errorcoderule, HttpContext context, HttpException httpException, VLogErrorCode rules)
        {
            // Mandatory Fields
            this.HttpStatusCodeDescription = errorcoderule.Message;
            this.WebHostHtmlMessage = new VXmlCData(httpException.GetHtmlErrorMessage());
            this.ErrorPriority = errorcoderule.Priority;

            // If the HTTP context is available, then capture the
            // collections that represent the state request.
            HttpRequest request = context.Request;

            this.AddHeader(rules, request);

            this.AddServerVariables(rules, request);

            this.AddContextItems(rules, context);

            this.AddQueryStringVariables(rules, request);

            this.AddFormVariables(rules, request);

            this.AddCookies(rules, request);

            this.AddApplicationStateVariables(context, rules);

            this.AddSessionStateVariables(context, rules);
        }
开发者ID:MGramolini,项目名称:vodca,代码行数:34,代码来源:VLogServerSideError.cs

示例10: SafeTryGetHtmlErrorMessage

 private static string SafeTryGetHtmlErrorMessage(HttpException exception)
 {
     if ((exception != null) && canGetHtmlErrorMessage)
     {
         try
         {
             return exception.GetHtmlErrorMessage();
         }
         catch (SecurityException exception2)
         {
             canGetHtmlErrorMessage = false;
             if (DiagnosticUtility.ShouldTraceWarning)
             {
                 DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Warning);
             }
         }
     }
     return null;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:19,代码来源:ServiceHostingEnvironment.cs


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