@ PiotrSzmyd прав, он частично зашифрован.«По умолчанию» происходит из поля Name
в Orchard.Web\App_Data\Sites\Default\Settings.txt
, а пути жестко закодированы в Orchard\FileSystems\Media\FileSystemStorageProvider.cs
.К сожалению, нет способа изменить поведение этого класса с помощью обработчиков или чего-то еще.Теперь есть 2 варианта
- изменить исходный код Orchard
- обойти его, добавив модуль, который обеспечивает пользовательскую реализацию
IStorageProvider
и при необходимости (означает путь к хранилищу носителянаходится вне структуры каталогов Orchard) дополнительный контроллер MVC для обслуживания файлов мультимедиа.
Я изменил путь хранения мультимедиа на \\<server>\Files$\<build_configuration>\Media
с помощью второй опции.
ПервыйВот основные части IStorageProvider
:
Пользовательская IStorageProvider
реализация
[Orchard.Environment.Extensions.OrchardSuppressDependency("Orchard.FileSystems.Media.FileSystemStorageProvider")] // adopted from AzureBlobStorageProvider.cs
public class FileSystemStorageProvider : Orchard.FileSystems.Media.IStorageProvider
{
private Orchard.FileSystems.Media.FileSystemStorageProvider mFileSystemStorageProvider;
public FileSystemStorageProvider(Orchard.Environment.Configuration.ShellSettings settings)
{
// use Orchard's default IStorageProvider for implementation
mFileSystemStorageProvider = new Orchard.FileSystems.Media.FileSystemStorageProvider(settings);
var lFileSystemStorageProviderType = mFileSystemStorageProvider.GetType();
// get media storage path, e.g. from configuration file
var lStoragePath = GetMediaStoragePath();
lStoragePath = System.IO.Path.Combine(lStoragePath, settings.Name);
// _storagePath is private read-only, so change it the hard way by using reflection
lFileSystemStorageProviderType
.GetField("_storagePath", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.SetValue(mFileSystemStorageProvider, lStoragePath);
string lVirtualPath = "~/Files/" + settings.Name + "/";
lFileSystemStorageProviderType
.GetField("_virtualPath", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.SetValue(mFileSystemStorageProvider, lVirtualPath);
string lPublicPath = mFileSystemStorageProvider.GetPublicUrl(null).Replace("/Media/" + settings.Name + "/", "/Files/" + settings.Name + "/");
lFileSystemStorageProviderType
.GetField("_publicPath", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.SetValue(mFileSystemStorageProvider, lPublicPath);
}
#region Implementation of IStorageProvider
public bool FileExists(string aPath)
{
return mFileSystemStorageProvider.FileExists(aPath);
}
...
#endregion
}
Эта пользовательская реализация отображает
- путь к хранилищу
\\<server>\Files$\<build_configuration>\Media
- виртуальный путь к
~/Files/Default/
- абсолютный путь к
/Files/Default/
В настоящее время возникла проблема.Orchard отображает URL-адреса мультимедиа как www.mysite.de/Files/Default...
, но в структуре каталогов Orchard нет каталога с именем Files.Теперь в игру вступает пользовательский маршрут.
Пользовательский маршрут
public class Routes : Orchard.Mvc.Routes.IRouteProvider
{
public System.Collections.Generic.IEnumerable<Orchard.Mvc.Routes.RouteDescriptor> GetRoutes()
{
Orchard.Mvc.Routes.RouteDescriptor[] lRoutes =
new Orchard.Mvc.Routes.RouteDescriptor[]
{
new Orchard.Mvc.Routes.RouteDescriptor()
{
Name = "Custom route for media files",
Priority = 10000,
Route = new System.Web.Routing.Route(
"Files/{*aRelativePath}",
new System.Web.Routing.RouteValueDictionary()
{
{"area", "MyModule"},
{"controller", "Media"},
{"action", "GetFile"}
},
new System.Web.Routing.RouteValueDictionary() {},
new System.Web.Routing.RouteValueDictionary() { {"area", "MyModule"} },
new System.Web.Mvc.MvcRouteHandler()
)
}
};
return lRoutes;
}
public void GetRoutes(System.Collections.Generic.ICollection<Orchard.Mvc.Routes.RouteDescriptor> arRoutes)
{
foreach (var lRouteDescriptor in GetRoutes())
arRoutes.Add(lRouteDescriptor);
}
}
Эта реализация маршрута обеспечивает перенаправление www.mysite.de/Files/Default...
на определенный медиа-контроллер, который выглядит следующим образом.:
Медиа контроллер
public class MediaController
{
public MediaController(Orchard.FileSystems.Media.IMimeTypeProvider aMimeTypeProvider)
{
mMimeTypeProvider = aMimeTypeProvider;
}
public System.Web.Mvc.ActionResult GetFile(string aRelativePath)
{
string lMediaStoragePath, lErrorMessage;
// get media storage path, e.g. from configuration file
if (GetMediaStoragePath(out lMediaStoragePath, out lErrorMessage))
{
string lFilename = System.IO.Path.Combine(lMediaStoragePath, aRelativePath);
string lMimeType = mMimeTypeProvider.GetMimeType(lFilename);
return File(lFilename, lMimeType);
}
else
return Content(lErrorMessage);
}
// private
private Orchard.FileSystems.Media.IMimeTypeProvider mMimeTypeProvider;
}