Is there a way to read from Response Headers without getting a PlatformNotSupportedException?

别来无恙 提交于 2019-12-24 03:27:35

问题


I am working on an Filter Attribute for ASP.Net MVC that will return a 304 response when the content has not been modified. It would be handy to be able to read the Last-Modified header value set in the Controller in order to accomplish this... there just seems to be one problem. I can't seem to find a way to read the headers when executing code like the following on Cassini [Visual Studio 2008 Dev Web Server]...

Response.AddHeader("Last-Modified", lastModified);
string getLastModified = Response.Headers.Get("Last-Modified");

I've also tried the following:

Response.AddHeader("Last-Modified", lastModified);
string getLastModified = Response.Headers["Last-Modified"];

Both return a PlatformNotSupportedException and indicate that they require "This operation requires IIS integrated pipeline mode."

Here are some details on the environment:

  • Framework Version: .Net 3.5 - SP1
  • IDE: Visual Studio 2008
  • Web Server: Cassini [Dev] and IIS6 [Production]

I'm probably missing a simple way to get this to work...
Thanks in advance,
Joe


回答1:


Response.Headers isn't supported with Cassini or IIS 6. This is true for several other recent features, too, such as Server Variables.

Solution:

  1. Do your development with a local version of IIS 7 by configuring a web site in IIS to point to your dev files, and setting the start URL for your project accordingly. You can use ports other than 80 if you need to, for multiple projects.

  2. Switch your production site to use IIS 7 (probably with Windows Server 2008). There are a bunch of other good reasons to upgrade, too, such as improved performance.

If an upgrade isn't possible, the only alternative I can think of is to write an ISAPI filter to make the header changes (in C++).



来源:https://stackoverflow.com/questions/1774249/is-there-a-way-to-read-from-response-headers-without-getting-a-platformnotsuppor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!