当前位置: 首页>>代码示例>>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;未经允许,请勿转载。