私はその人が匿名で、前もって詳細を提供していればファイルをダウンロードできると仮定しています。その場合は、Authorization属性を無視して独自の属性を記述します。ここに簡単な例があります。それは設定されるクッキーに依存します。
public class CheckEmailAddressAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var request = filterContext.HttpContext.Request;
// if the cookie isn't set the a user never provided their details
if (request.Cookies["mycookiename"] == null)
{
// Set it to the correct result, to redirect the user to provide their email address
filterContext.Result = new ViewResult { ViewName = "GetEmailAddress" };
filterContext.HttpContext.Response.AppendCookie(new HttpCookie("mycookiename", "true"));
}
else
{
// Don't do anything, the user already provided their email address
}
}
}
ダウンロードしたコントローラで次のように指定します。
public class DownloadController : Controller
{
[CheckEmailAddress]
public ActionResult Download(string name)
{
// Implement download
}
}
残っているのは、電子メールアドレスが設定されているときにクッキーを設定することだけです。私はあなたがそれをする方法を知っていると仮定します。また、「returnUrl」パラメータがあることを確認して、電子メールアドレスを入力した後でダウンロードページにリダイレクトすることもできます。
EDIT OP 1として、私たちはここで更新クラスがあり、人はその詳細を入力した場合を除き、クッキーを設定する必要はありません。
public class CheckEmailAddressAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var request = filterContext.HttpContext.Request;
// if the cookie isn't set the a user never provided their details
if (request.Cookies["mycookiename"] == null)
{
// Set it to the correct result, to redirect the user to provide their email address
filterContext.Result = new ViewResult { ViewName = "GetEmailAddress" };
// filterContext.HttpContext.Response.AppendCookie(new HttpCookie("mycookiename", "true"));
}
else
{
// Don't do anything, the user already provided their email address
}
}
}
ロールを使用する必要があります。 [http://stackoverflow.com/questions/6404254/mvc-3-dynamic-authorization-of-multiple-roles-and-users][1] [1]:のhttp://のstackoverflow。 com/questions/6404254/mvc-3-multiple-roles-and-usersの動的承認 –