Asp.net mvc 使用自定义TextWriter时,Sitecore MVC OutputStream不可用

Asp.net mvc 使用自定义TextWriter时,Sitecore MVC OutputStream不可用,asp.net-mvc,sitecore,asp.net-mvc-routing,sitecore8,sitecore-mvc,Asp.net Mvc,Sitecore,Asp.net Mvc Routing,Sitecore8,Sitecore Mvc,根据这一回答: 我在提交表格时无法提供vCard @using (Html.BeginRouteForm(MvcSettings.SitecoreRouteName, FormMethod.Post, new { name = "vCard_verify", @class = "vCardVerify" })) { @Html.AntiForgeryToken() @Html.Sitecore().FormH

根据这一回答:

我在提交表格时无法提供vCard

@using (Html.BeginRouteForm(MvcSettings.SitecoreRouteName, FormMethod.Post, new { name = "vCard_verify", @class = "vCardVerify" }))
            {
                @Html.AntiForgeryToken()
                @Html.Sitecore().FormHandler("Content", "vCard")
                @Html.Hidden("vCardGuid")

                <div id="g-recaptcha-vCard"></div>
            }
我得到的错误是:使用自定义TextWriter时,OutputStream不可用。
我相信在调用我的操作之前已经发送了标题,但是我不确定替代方法是什么?如何强制下载文件并使用Sitecore 8 MVC加载当前页面?

事实证明,在Sitecore开始构建实际页面之前,我必须重新路由到一个新操作,以便能够首先传递我自己的标题

因此,我的post功能更改为:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult vCard(string vCardGuid)
{
      if (string.IsNullOrEmpty(vCardGuid))
          return Redirect("/People");

      return RedirectToAction("DownloadvCard", new { vGuid = vCardGuid });
}
新的下载vCard功能基本上是旧的vCard功能

[HttpGet]
public vCardResult DownloadvCard(string vGuid)
{
    var context = new SitecoreContext();
    var person = context.GetItem<Person>(vGuid);
    Item personItem = Database.GetDatabase("master").GetItem(ID.Parse(vGuid));
    //Photo
    ImageField img = personItem.Fields["Person Thumbnail"];
    MediaItem image = new MediaItem(img.MediaItem);
    var imageURL = MediaManager.GetMediaUrl(image, new MediaUrlOptions() { AbsolutePath = true, AlwaysIncludeServerUrl = true });

    //Url
    var options = LinkManager.GetDefaultUrlOptions();
    options.AlwaysIncludeServerUrl = true;
    string url = LinkManager.GetItemUrl(personItem, options);

    Location office = new Location();
    foreach (var loc in person.Offices)
    {
        office = loc;
        break;
    }

    var card = new VCard();
    card.FirstName = person.First_Name;
    card.LastName = person.Last_Name;
    card.StreetAddress = office.Location_Address;
    card.StreetAddress2 = office.Location_Address_2;
    card.City = office.Location_City;
    card.State = office.Location_State;
    card.Zip = office.Location_Zip;
    card.CountryName = "USA";
    card.Organization = "O'Connor Davies";
    card.JobTitle = person.Person_Title;
    card.Phone = person.Phone;
    card.Fax = office.Location_Fax;
    card.Image = imageURL.Replace(".ashx",".png");
    card.HomePage = url;
    card.Email = person.Email_Address;


    return new vCardResult(card);
}
[HttpGet]
公共vCardResult下载vCard(字符串vGuid)
{
var context=new SitecoreContext();
var person=context.GetItem(vGuid);
Item personite=Database.GetDatabase(“master”).GetItem(ID.Parse(vGuid));
//照片
ImageField img=personItem.Fields[“个人缩略图”];
MediaItem图像=新的MediaItem(img.MediaItem);
var imageURL=MediaManager.GetMediaUrl(图像,新MediaUrlOptions(){AbsolutePath=true,AlwaysIncludeServerUrl=true});
//网址
var options=LinkManager.GetDefaultUrlOptions();
options.AlwaysIncludeServerUrl=true;
字符串url=LinkManager.GetItemUrl(personItem,选项);
地点办公室=新地点();
foreach(var loc个人办公室)
{
办公室=loc;
打破
}
var卡=新VCard();
card.FirstName=person.First\u Name;
card.LastName=person.Last_Name;
card.StreetAddress=office.Location\u地址;
card.streetaddress 2=office.Location\u Address\u 2;
card.City=office.Location\u City;
card.State=office.Location\u State;
card.Zip=office.Location\u-Zip;
card.CountryName=“美国”;
card.Organization=“O'Connor Davies”;
card.JobTitle=person.person\u Title;
card.Phone=person.Phone;
card.Fax=office.Location\u传真;
card.Image=imageURL.Replace(“.ashx”,“.png”);
card.HomePage=url;
card.Email=person.Email\u地址;
返回新的vCardResult(卡);
}
其余的都一样。
快乐编码;)

这很好,但在Sitecore访问受到限制的CD实例上不起作用:“您没有查看此目录或页面的权限。”因为执行重定向的方法ping的默认路由是/Sitecore/shell/api/Sitecore/ControllerName/DownloadvCardI,我面临类似问题。正如上面评论中提到的@Marcel,CD实例正在阻塞。有解决这个问题的最终方案吗?
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult vCard(string vCardGuid)
{
      if (string.IsNullOrEmpty(vCardGuid))
          return Redirect("/People");

      return RedirectToAction("DownloadvCard", new { vGuid = vCardGuid });
}
[HttpGet]
public vCardResult DownloadvCard(string vGuid)
{
    var context = new SitecoreContext();
    var person = context.GetItem<Person>(vGuid);
    Item personItem = Database.GetDatabase("master").GetItem(ID.Parse(vGuid));
    //Photo
    ImageField img = personItem.Fields["Person Thumbnail"];
    MediaItem image = new MediaItem(img.MediaItem);
    var imageURL = MediaManager.GetMediaUrl(image, new MediaUrlOptions() { AbsolutePath = true, AlwaysIncludeServerUrl = true });

    //Url
    var options = LinkManager.GetDefaultUrlOptions();
    options.AlwaysIncludeServerUrl = true;
    string url = LinkManager.GetItemUrl(personItem, options);

    Location office = new Location();
    foreach (var loc in person.Offices)
    {
        office = loc;
        break;
    }

    var card = new VCard();
    card.FirstName = person.First_Name;
    card.LastName = person.Last_Name;
    card.StreetAddress = office.Location_Address;
    card.StreetAddress2 = office.Location_Address_2;
    card.City = office.Location_City;
    card.State = office.Location_State;
    card.Zip = office.Location_Zip;
    card.CountryName = "USA";
    card.Organization = "O'Connor Davies";
    card.JobTitle = person.Person_Title;
    card.Phone = person.Phone;
    card.Fax = office.Location_Fax;
    card.Image = imageURL.Replace(".ashx",".png");
    card.HomePage = url;
    card.Email = person.Email_Address;


    return new vCardResult(card);
}