У меня есть действие в контроллере, который получает идентификатор параметра, как показано ниже.
[AuthorizeOrder(AttributeHelper.Orders.Entity, AttributeHelper.Orders.Parameter.id)]
public ActionResult OrderModal(int id, bool dl = false)
{
var order = _orderReader.Get(id);
.............
}
ниже - мой пользовательский фильтр авторизации, который выдает ошибку в последней строке, когда я пытаюсь получить идентификатор из параметра. Я получаю Id, когда в actionresult в контроллере, однако в атрибуте я не получите запрошенный Id.
public class AuthorizeOrder : AuthorizeAttribute
{
protected string entity;
public string Entity
{
get { return this.entity; }
}
protected string key;
public string Key
{
get { return this.key; }
}
protected bool isLookingAtOwnData;
public bool IsLookingAtOwnData
{
get { return this.IsLookingAtOwnData; }
set { this.isLookingAtOwnData = value; }
}
public string Value { get; set; }
public AuthorizeOrder(string Entity, string key)
{
this.entity = Entity;
this.key = key;
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
isLookingAtOwnData = true;
if (string.IsNullOrEmpty(Entity) || string.IsNullOrEmpty(Key))
throw new Exception("Incorrect use of Attribute: ResourceType and Resource Key are required for AuthorizeInvoice Attribute");
var isAuthorized = base.AuthorizeCore(httpContext);
if (isAuthorized)
{
var _customerContext = DependencyResolver.Current.GetService<ICustomerContext>();
switch (Entity)
{
case AttributeHelper.Orders.Entity:
{
var orderId = int.Parse(HttpContext.Current.Request.Params[key]);