本文整理汇总了C#中IHttpRequest.WriteContent方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpRequest.WriteContent方法的具体用法?C# IHttpRequest.WriteContent怎么用?C# IHttpRequest.WriteContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpRequest
的用法示例。
在下文中一共展示了IHttpRequest.WriteContent方法的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))
//.........这里部分代码省略.........