解决方法由于控制器设计而丢失了HttpContext

时间:2018-06-30 10:58:20

标签: asp.net-mvc httpcontext

我正面临有关HttpContext的问题,该问题由于设计而丢失了。

我使用 AutoFac 在控制器中注入一组不同的控制器。 该控制器的唯一职责是遍历实现View的这组控制器_ previewPresentations ,并在最后调用特定的实现。

public class OfferingController : OfferingBaseController
{
    private readonly IEnumerable<IOfferingPresentation> _previewPresentations;
    public OfferingController(IEnumerable<IOfferingPresentation> offeringPresentations)
            : base()
    {
        _offeringPresentation = offeringPresentations;
    }

    public async Task<ActionResult> View(Guid? id)
    {

        foreach (var item in _previewPresentations)
        {
            if (item.IsImplentation(id))
            {
               await item.View(id).ConfigureAwait(false);
            }
        }

        return View("Error");
    }

}

到目前为止,该方法工作正常,但是由于OfferingBaseController为空,所有依赖于Request中HttpContext的函数都失败了:

public class OfferingBaseController:Controller
{
  protected string GetCookieValue(string key)
        {
            var cookie = Request.Cookies[key];

            return cookie?.Value;
        }
}

我认为这是因为:

 await item.View(id).ConfigureAwait(false);

以某种方式HttpContext丢失并且无法在我的基本控制器中访问

OfferingBaseController.

有没有解决方法?

0 个答案:

没有答案
相关问题