Выполнения GAC с Полным Доверием и могут использоваться приложениями за пределами Вашего веб-приложения. Например, Timer Jobs в Sharepoint должны быть в GAC, потому что sptimer обслуживание является отдельным процессом.
"Полная Доверительная" Часть является также возможным источником для проблем безопасности. Несомненно, можно работать с Безопасностью доступа к коду, но я не вижу, что слишком много блоков используют CAS, к сожалению: (/Папка мусорного ведра может быть заблокирована вниз к Носителю, который обычно прекрасен.
Daniel Larson имеет сообщение на CAS также , который детализирует различия немного больше.
Something like this probably:
[AttributeUsage(AttributeTargets.All)]
public sealed class ValidateAsClientAttribute : ActionFilterAttribute
{
private readonly NameValueCollection formData;
public NameValueCollection FormData{ get { return formData; } }
public ValidateAsClientAttribute (NameValueCollection formData)
{
this.formData = formData;
}
public override void OnActionExecuting
(ActionExecutingContext filterContext)
{
string username = formData["username"];
if (string.IsNullOrEmpty(username))
{
filterContext.Controller.ViewData.ModelState.AddModelError("username");
}
// you get the idea
}
}
And use it like this:
[ValidateAsClient(HttpContext.Request.Form)]
You should override the following method.
public override void OnActionExecuting(ActionExecutingContext context)
And from the context object, access your post data.
I would solve this problem with a custom binder in ASP.NET MVC.
Suppose your action will have the following signature.
public ActionResult MyAction(MyParameter param)
{
if(param.isValid)
return View("valid");
else
return View("invalid");
}
MyParam class:
public class MyParameter
{
public string UserName{get;set;}
public string Password {get;set;}
public bool isValid
{
//check if password and username is valid.
}
}
An then the custom binder
public class CustomBinder:IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var p = new MyParam();
// extract necessary data from the bindingcontext like
p.UserName = bindingContext.ValueProvider["username"] != null
? bindingContext.ValueProvider["username"].AttemptedValue
: "";
//initialize other attributes.
}
}
I don't think it's a good idea to use an ActionFilterAttribute
in this case. And what you want to do is definitely not the same as Authorize
attribute does.
The Authorize
attribute just injects a common logic into a controller/action. Which is :
Redirect to login page, if the user is not logged in. Else let the action be executed.
Your ClientLogin
action does just what it's supposed to do at the moment.
It would be a bad design to carry that logic over to an ActionFilterAttribute
.