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


C# IHttpRequest.SetResponseContentType方法代码示例

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


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

示例1: HandleRequest

 /*
  * Called to handle a given web request.  The system uses IHttpRequest to allow for different web server 
  * systems.  It checks to see if the url is for jquery,json or backbone, if none of those, it generates the required model 
  * javascript for the given url, as specified by an attribute or attributes in Models, that define the 
  * url that the model/view/collection javascript is available on.
  * If the call is not for javascript it processes the given action using the http method (GET = load,
  * DELETE = delete, POST = create, PUT = update, SELECT = SelectList, SMETHOD = StaticMethodCall, METHOD = MethodCall)
  */
 public static void HandleRequest(IHttpRequest request)
 {
     Logger.Debug("Handling backbone request for path " + request.URL.ToString());
     int status=-1;
     string message=null;
     bool allowNullResponse = false;
     if (request.URL.AbsolutePath.EndsWith(".js") && request.Method.ToUpper() == "GET")
     {
         if (request.IsJsURLAllowed(Uri.UnescapeDataString(request.URL.AbsolutePath), out status, out message))
         {
             message = null;
             request.SetResponseContentType("text/javascript");
             if (Uri.UnescapeDataString(request.URL.AbsolutePath) == (_jqueryURL == null ? "" : _jqueryURL))
             {
                 Logger.Trace("Sending jquery javascript response through backbone handler");
                 request.SetResponseStatus(200);
                 request.WriteContent(Utility.ReadEmbeddedResource("Org.Reddragonit.BackBoneDotNet.resources.jquery.min.js",false));
                 request.SendResponse();
             }
             else if (Uri.UnescapeDataString(request.URL.AbsolutePath) == (_jsonURL == null ? "" : _jsonURL))
             {
                 Logger.Trace("Sending json javascript response through backbone handler");
                 request.SetResponseStatus(200);
                 request.WriteContent(Utility.ReadEmbeddedResource("Org.Reddragonit.BackBoneDotNet.resources.json2.min.js",false));
                 request.SendResponse();
             }
             else if (Uri.UnescapeDataString(request.URL.AbsolutePath) == (_backboneURL == null ? "" : _backboneURL))
             {
                 Logger.Trace("Sending modified backbone javascript response through backbone handler");
                 request.SetResponseStatus(200);
                 request.WriteContent(Utility.ReadEmbeddedResource("Org.Reddragonit.BackBoneDotNet.resources.backbone_combined.min.js",false));
                 request.SendResponse();
             }
             else
             {
                 bool found = false;
                 lock (_CachedJScript)
                 {
                     if (_CachedJScript.ContainsKey(request.URL.Host + Uri.UnescapeDataString(request.URL.AbsolutePath)))
                     {
                         Logger.Trace("Sending cached javascript response for path " + request.URL.Host + request.URL.AbsolutePath);
                         found = true;
                         request.SetResponseStatus(200);
                         request.WriteContent((string)_CachedJScript[request.URL.Host + Uri.UnescapeDataString(request.URL.AbsolutePath)].Value);
                         request.SendResponse();
                     }
                 }
                 if (!found)
                 {
                     Logger.Trace("Buidling model javascript for path " + request.URL.Host + Uri.UnescapeDataString(request.URL.AbsolutePath));
                     StringBuilder sb = new StringBuilder();
                     foreach (Type t in Utility.LocateTypeInstances(typeof(IModel)))
                     {
                         foreach (ModelJSFilePath mj in t.GetCustomAttributes(typeof(ModelJSFilePath), false))
                         {
                             if ((mj.Host == "*" || mj.Host == request.URL.Host) && 
                                 (mj.Path == Uri.UnescapeDataString(request.URL.AbsolutePath)||mj.MinPath==Uri.UnescapeDataString(request.URL.AbsolutePath)))
                             {
                                 Logger.Trace("Appending model " + t.FullName + " to path " + request.URL.Host + Uri.UnescapeDataString(request.URL.AbsolutePath));
                                 sb.Append(_GenerateModelJSFile(t, request.URL.Host, mj.MinPath == Uri.UnescapeDataString(request.URL.AbsolutePath) || Settings.Default.CompressAllJS));
                             }
                         }
                     }
                     request.SetResponseStatus(200);
                     request.WriteContent(sb.ToString());
                     lock (_CachedJScript)
                     {
                         if (!_CachedJScript.ContainsKey(request.URL.Host + request.URL.AbsolutePath))
                             _CachedJScript.Add(request.URL.Host + Uri.UnescapeDataString(request.URL.AbsolutePath), new CachedItemContainer(sb.ToString()));
                     }
                     request.SendResponse();
                 }
             }
         }
         else
             _SetSecurityError(out status, out message);
     }
     else
     {
         Object ret = null;
         switch (request.Method.ToUpper())
         {
             case "GET":
                 Logger.Trace("Attempting to handle GET request");
                 if (_RPC_SELECT.IsMatch(request.Method.ToUpper(), request.URL.Host, request.URL.AbsolutePath + (request.URL.Query != "" ? request.URL.Query : "")))
                 {
                     Logger.Trace("Handling request as a model list method");
                     foreach (sModelListCall mlc in _ModelListCalls)
                     {
                         if (mlc.HandlesRequest(request))
                         {
                             if (request.IsListAllowed(mlc.ModelType, out status, out message))
//.........这里部分代码省略.........
开发者ID:marquismark,项目名称:backbone-dotnet,代码行数:101,代码来源:RequestHandler.cs


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