1
在我們的Sitecore解決方案中下載媒體項目時,我們一直面臨一個問題。我們想要認證下載媒體的用戶。如果用戶無權訪問該文件,我們需要重定向該用戶/取消下載。Sitecore - 根據請求獲取有關媒體項目的信息
決定重定向的東西是該媒體項目(帶ID的字段)的元數據。
我們做了一個模塊:
<add type="Lib.CustomMediaRequestSessionModule, Lib" name="CustomMediaRequestSessionModule" />
代碼:
public class CustomMediaRequestSessionModule : IHttpModule
{
public void Init(HttpApplication application)
{
application.BeginRequest += Application_BeginRequest;
}
private void Application_BeginRequest(object source, EventArgs e)
{
var application = (HttpApplication)source;
var currentContext = HttpContext.Current;
if (currentContext.Request.Url.ToString().ToLower().Contains("/~/media/"))
{
//Here we want to authenticate the user
}
}
public void Dispose()
{
}
}
我們從請求得到的唯一信息是文件路徑。 「/~/media/path/to/file.doc」。
是否有另一種方式從媒體項目獲取更多信息?在Sitecore中執行同樣的操作是否有更好的方法?