How can I create a custom AuthorizeAttribute that specifies a message in the form of a string parameter and then passes that along to the login page?
For example, ideally it would be cool to do this:
[Authorize(Message = "Access to the blah blah function requires login. Please login or create an account")]
public ActionResult SomeAction()
{
return View();
}
Then, in the Login action, I could do something like this:
public ActionResult Login(string message = "")
{
ViewData.Message = message;
return View();
}
And finally in the view I can do this:
@if (!String.IsNullOrEmpty(ViewData.Message))
{
<div class="message">@ViewData.Message</div>
}
<form> blah blah </form>
Basically I want to pass a custom message to the login page so I can display a message specific to what the user is trying to access at that particular time.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…