问题
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:
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.
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