В HttpListener получаю запрос от клиента, в AbsolutePath беру путь запроса. Как мне узнать, клиент запрашивает путь или файл. Если файл. то вернуть клиенту содержимое с нужным миме-типом?
Например иконку я вывожу так:
if (req.Url.AbsolutePath == "/favicon.ico")
{
string iconFilePath = publicDir + "/favicon.ico";
byte[] fileData = {};
try
{
fileData = System.IO.File.ReadAllBytes(fileName);
context.Response.ContentType = "image/png";
context.Response.ContentLength64 = fileData.Length;
context.Response.OutputStream.Write(fileData, 0, fileData.Length);
}
catch (Exception ex)
{
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
Console.WriteLine("Error: " + ex.Message + " " + ex.StackTrace);
}
finally
{
context.Response.OutputStream.Close();
}
continue;
}
а если это путь, то вызвать Класс:Метод в зависимости от запрошенного пути