Carrotware.CMS.Core.SiteData.ManuallyWriteDefaultFile C# (CSharp) Метод

ManuallyWriteDefaultFile() публичный статический Метод

public static ManuallyWriteDefaultFile ( HttpContext context, Exception objErr ) : void
context System.Web.HttpContext
objErr System.Exception
Результат void
        public static void ManuallyWriteDefaultFile(HttpContext context, Exception objErr)
        {
            Assembly _assembly = Assembly.GetExecutingAssembly();

            string sBody = String.Empty;

            using (StreamReader oTextStream = new StreamReader(_assembly.GetManifestResourceStream("Carrotware.CMS.Core.SiteContent.Default.htm"))) {
                sBody = oTextStream.ReadToEnd();
            }
            try {
                if (CurretSiteExists) {
                    sBody = sBody.Replace("{TIME_STAMP}", CurrentSite.Now.ToString());
                }
            } catch { }
            sBody = sBody.Replace("{TIME_STAMP}", DateTime.Now.ToString());

            if (objErr != null) {
                sBody = sBody.Replace("{LONG_NAME}", FormatToHTML(" [" + objErr.GetType().ToString() + "] " + objErr.Message));

                if (objErr.StackTrace != null) {
                    sBody = sBody.Replace("{STACK_TRACE}", FormatToHTML(objErr.StackTrace));
                }
                if (objErr.InnerException != null) {
                    sBody = sBody.Replace("{CONTENT_DETAIL}", FormatToHTML(objErr.InnerException.Message));
                }
            }

            sBody = sBody.Replace("{STACK_TRACE}", "");
            sBody = sBody.Replace("{CONTENT_DETAIL}", "");

            sBody = sBody.Replace("{SITE_ROOT_PATH}", SiteData.AdminFolderPath);

            context.Response.ContentType = "text/html";
            context.Response.Clear();
            context.Response.BufferOutput = true;

            context.Response.Write(sBody);
            context.Response.Flush();
            context.Response.End();
        }

Usage Example

        private void RewriteCMSPath(HttpContext context, string sTmplateFile, string sQuery)
        {
            try {
                if (string.IsNullOrEmpty(sVirtualReqFile))
                {
                    sVirtualReqFile = SiteData.DefaultDirectoryFilename;
                }
                if (string.IsNullOrEmpty(sTmplateFile))
                {
                    sTmplateFile = SiteData.DefaultTemplateFilename;
                }

                context.RewritePath(sVirtualReqFile, string.Empty, sQuery);

                //cannot work in med trust
                //Page hand = (Page)PageParser.GetCompiledPageInstance(sFileRequested, context.Server.MapPath(sRealFile), context);

                Page hand = (Page)BuildManager.CreateInstanceFromVirtualPath(sTmplateFile, typeof(Page));
                hand.PreRenderComplete += new EventHandler(hand_PreRenderComplete);
                hand.ProcessRequest(context);
            } catch (Exception ex) {
                //assumption is database is probably empty / needs updating, so trigger the under construction view
                if (DatabaseUpdate.SystemNeedsChecking(ex) || DatabaseUpdate.AreCMSTablesIncomplete())
                {
                    SiteData.ManuallyWriteDefaultFile(context, ex);
                }
                else
                {
                    //something bad has gone down, toss back the error
                    throw;
                }
            }
        }