I have an action in a controller which returns a file to download, however this action doesnt show on Glimpse's history.

Is there a way to make it show up?

This is the code:

   public ActionResult DownloadCv(string fileName)
        {


            string filepath = string.Format("{0}/{1}", _appSettings.CvsDirectory, fileName);
            const string contentType = "application/msword";

            return File(filepath, contentType, fileName);
        }
有帮助吗?

解决方案

The reason its not currently showing up is because of the content type policy thats in place by default. If you have a look at the following documentation, you will see the Content Types section which describes what needs to be done:

<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
    <runtimePolicies>
      <contentTypes>
        <add contentType="application/msword"/> 
      </contentTypes>
    </runtimePolicies>
</glimpse>

The problem you may run into here is that with the way the content type policy is implemented, it returns RuntimePolicy.On. This means that the glimpse client will try and embedded in the result. What you actually want is RuntimePolicy.PersistResults. So after you add the above contentType to the runtimePolicies section. I would also create the following and drop it into your project, Glimpse should pick up the rest.

public class MsWordContentTypePolicy : IRuntimePolicy 
{  
    public RuntimeEvent ExecuteOn
    {
        get { return RuntimeEvent.EndRequest; }
    }

    public RuntimePolicy Execute(IRuntimePolicyContext policyContext)
    { 
        var contentType = policyContext.RequestMetadata.ResponseContentType.ToLowerInvariant();

        return contentType == "application/msword" ? RuntimePolicy.PersistResults : RuntimePolicy.On; 
    }
}

其他提示

This has since been incorporated in Glimpse, such that you can just use:

<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
   <runtimePolicies>
     <contentTypes>
       <add contentType="application/msword" runtimePolicy="PersistResults" />
    </contentTypes>
  </runtimePolicies>    
</glimpse>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top