當前位置: 首頁>>代碼示例>>C#>>正文


C# HttpApplication.IsAjax方法代碼示例

本文整理匯總了C#中System.Web.HttpApplication.IsAjax方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpApplication.IsAjax方法的具體用法?C# HttpApplication.IsAjax怎麽用?C# HttpApplication.IsAjax使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Web.HttpApplication的用法示例。


在下文中一共展示了HttpApplication.IsAjax方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: StandardResponse

        public string StandardResponse(HttpApplication application)
        {
            IDictionary<string, object> data;
            if (!application.TryGetData(out data)) return "Error: No Glimpse Data Found";

            var json = JsSerializer.Serialize(data); //serialize data to Json
            json = Sanitizer.Sanitize(json);

            //if ajax request, render glimpse data to headers
            if (application.IsAjax())
            {
                application.Response.AddHeader(GlimpseConstants.HttpHeader, json);
            }
            else
            {
                var html = string.Format(
                    @"<script type='text/javascript' id='glimpseData'>var glimpse = {0};</script>", json);
                html += @"<script type='text/javascript' id='glimpseClient' src='/Glimpse/glimpseClient.js'></script>";
                html += @"<!--<img src='/Glimpse/glimpseSprite.png'/>-->";
                application.Response.Write(html);
            }

            return json;
        }
開發者ID:avanderhoorn,項目名稱:Glimpse,代碼行數:24,代碼來源:GlimpseResponders.cs

示例2: Persist

        private void Persist(string json, HttpApplication ctx, Guid requestId)
        {
            if (Configuration.SaveRequestCount <= 0) return;

            var store = ctx.Application;

            //clientName, longtime, url,
            var queue = store[GlimpseConstants.JsonQueue] as Queue<GlimpseRequestMetadata>;

            if (queue == null)
                store[GlimpseConstants.JsonQueue] =
                    queue = new Queue<GlimpseRequestMetadata>(Configuration.SaveRequestCount);

            if (queue.Count == Configuration.SaveRequestCount) queue.Dequeue();

            var browser = ctx.Request.Browser;
            queue.Enqueue(new GlimpseRequestMetadata
                              {
                                  Browser = string.Format("{0} {1}", browser.Browser, browser.Version),
                                  ClientName = ctx.GetClientName(),
                                  Json = json,
                                  RequestTime = DateTime.Now.ToLongTimeString(),
                                  RequestId = requestId,
                                  IsAjax = ctx.IsAjax().ToString(),
                                  Url = ctx.Request.RawUrl,
                                  Method = ctx.Request.HttpMethod
                              });
        }
開發者ID:mastoj,項目名稱:Glimpse,代碼行數:28,代碼來源:Module.cs

示例3: StandardResponse

        public string StandardResponse(HttpApplication application, Guid requestId)
        {
            IDictionary<string, object> data;
            if (!application.TryGetData(out data)) return "Error: No Glimpse Data Found";

            var sb = new StringBuilder("{");
            foreach (var item in data)
            {
                try
                {
                    var dataString = JsSerializer.Serialize(item.Value);
                    sb.Append(string.Format("\"{0}\":{1},", item.Key, dataString));
                }
                catch(Exception ex)
                {
                    var message = ex.Message;

                    if (ex is InvalidOperationException)
                        sb.Append(string.Format("\"{0}\":\"{1} : {2}<br/><span style='color:red;'>Please implement an IGlimpseConverter for the type mentioned above, or one of its base types, to fix this problem. More info on a better experience for this coming soon, keep an eye on <a href='http://getGlimpse.com' target='main'>getGlimpse.com</a></span>\",", item.Key, ex.GetType().Name, message));
                    else
                        sb.Append(string.Format("\"{0}\":\"{1} : {2}\",", item.Key, ex.GetType().Name, message));
                }
            }

            //Add exceptions tab if needed
            var exceptions = application.GetWarningStore();
            if (exceptions.Count > 1)
            {
                var dataString = JsSerializer.Serialize(exceptions);
                sb.Append(string.Format("\"{0}\":{1},", "Glimpse Warnings", dataString));
            }

            if (sb.Length > 1) sb.Remove(sb.Length - 1, 1);
            sb.Append("}");

            //var json = JsSerializer.Serialize(data); //serialize data to Json
            var json = sb.ToString();
            json = Sanitizer.Sanitize(json);

            //if ajax request, render glimpse data to headers
            if (application.IsAjax())
            {
                application.Response.AddHeader(GlimpseConstants.HttpHeader, requestId.ToString());
            }
            else
            {
                var html = string.Format(
                    @"<script type='text/javascript' id='glimpseData' data-glimpse-requestID='{1}'>var glimpse = {0};</script>", json, requestId);
                html += @"<script type='text/javascript' id='glimpseClient' src='" + RootPath + "glimpseClient.js'></script>";
                application.Response.Write(html);
            }

            return json;
        }
開發者ID:Talljoe,項目名稱:Glimpse,代碼行數:54,代碼來源:GlimpseResponders.cs


注:本文中的System.Web.HttpApplication.IsAjax方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。