0

アクションメソッドによって返されるファイルの最終変更日を取得したい。フルファイルパスが必要だと思います。FilePathResultプロパティがありますFileName

このプロパティは完全なファイルパスを返しますか、それとも名前だけを返しますか?もしそうなら、どういうわけかそのファイルへのフルパスを取得できますか?

ありがとう!

4

1 に答える 1

3

ファイルへのフルパスを返します。例:

[MyActionFilter]
public ActionResult Index()
{
    return File(Server.MapPath("~/web.config"), "text/xml");
}

その後:

public class MyActionFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        var fileResult = filterContext.Result as FilePathResult;
        if (fileResult != null)
        {
            // here you will get the full absolute path to the file,
            // for example c:\inetpub\wwwroot\MvcApplication1\web.config
            string fileName = fileResult.FileName;
        }
    }
}
于 2013-02-17T17:34:12.070 に答える