本文整理汇总了C#中RouteHandler.HandleDefaultFileRoute方法的典型用法代码示例。如果您正苦于以下问题:C# RouteHandler.HandleDefaultFileRoute方法的具体用法?C# RouteHandler.HandleDefaultFileRoute怎么用?C# RouteHandler.HandleDefaultFileRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteHandler
的用法示例。
在下文中一共展示了RouteHandler.HandleDefaultFileRoute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateResponse
/// <summary>
/// Based on request URI, method, and headers; form an appropriate response and carry out necessary actions on the server
/// </summary>
private RSResponse GenerateResponse()
{
var handler = new RouteHandler(_request.HttpMethod);
//ReServer (RS) response object
// Class used to build the raw output
// which will be fed into the HttpResponse OutputStream
RSResponse rsResponse = new RSResponse();
// Check authentication details and return early if not valid
if (!rsRequest.IsAuthorised)
{
return new StatusCodeResponse(HttpStatusCode.Unauthorized);
}
// Check first whether it is a dir
if (Directory.Exists(rsRequest.LocalPath))
{
Output.Write("Directory");
// localPath is a directory:
// Check it ends with a slash
if (rsRequest.PathEndsInSlash)
{
Output.Write("Getting default file");
// Folder root requested:
// Search configured list of default pages
// and perform correct action
rsResponse = handler.HandleDefaultFileRoute(rsRequest.LocalPath, rsRequest.AcceptTypes);
}
else
{
// Re-target the request to the directory itself
// to give correct behaviour when child files are requested
Output.Write(" Lacks terminating slash; redirecting...");
_response.Redirect(_request.Url.AbsoluteUri + '/');
rsResponse = new RedirectionResponse();
}
}
else
{
//Return the requested file
// or perform actions on it as a resource (depending on HttpMethod)
rsResponse = handler.HandleFileRoute(rsRequest, _request.InputStream);
}
//If request was good and statuscode has not been assigned, assign 200
if (rsResponse.Satisfied)
{
if ((int)rsResponse.StatusCode == 0)
{
rsResponse.StatusCode = HttpStatusCode.OK;
}
}
else
{
//If not found, return error or debug info
//TODO change to 404 response?
rsResponse = new TextResponse(rsRequest.Website.Local, _request, HttpStatusCode.NotFound);
}
//Convert the response to a client-preferred Content-Type
// if it actually has content (i.e. not a redirect or error message)
if (rsResponse.HasContent)
{
rsResponse = TryConvertToAcceptableContentType(rsResponse);
_response.ContentType = rsResponse.ContentType.ToString();
}
/*
Copy details to the real HTTP Response object
*/
// Response code (if set)
if (rsResponse.StatusCode != 0)
{
_response.StatusCode = (int)rsResponse.StatusCode;
}
// Additional headers added by the RSResponse
if (rsResponse.AdditionalHeaders != null)
{
foreach (var h in rsResponse.AdditionalHeaders)
{
_response.AppendHeader(h.Key, h.Value);
}
}
return rsResponse;
}