我正在尝试使用HttpHandler从一个ASP.NET Web应用程序将QuickTime视频流式传输到iPhone.从IIS 5.1(Windows XP)托管Web应用程序时,视频播放器将打开,然后显示错误"服务器未正确配置".但是,使用IIS 7.5(Windows 7)时,视频播放正常.
生产环境正在运行IIS 6.0并且存在同样的问题,尝试通过Mobile Safari在iPhone上播放视频会显示上述错误.
我检查了Http Headers,它们在两个服务器之间看起来几乎是相同的(除了一些,比如Server头,显然会有所不同),除了它们以不同的顺序出现,尽管我怀疑这个造成了这个问题.
根据Google网上论坛上的这个帖子,添加'Accept-Ranges:bytes'标题会有所帮助,尽管这对我们没有任何影响.我还添加了ETag标题,没有任何运气.
实际负责发送文件的代码如下所示:
Context.Response.Buffer = true;
Context.Response.ContentType = "video/x-m4v";
Context.Response.AppendHeader("Content-Disposition", "filename=\"Video.m4v\"");
Context.Response.AppendHeader("Content-Length", "23456789");
Context.Response.AppendHeader("Accept-Ranges", "bytes");
Context.Response.AppendHeader("ETag", GetETag(path));
Context.Response.TransmitFile(path);
Run Code Online (Sandbox Code Playgroud)
传输文件的上述代码似乎运行正常,视频文件在所有桌面浏览器中以及在Windows 7上从IIS 7.5托管时正确播放.只有在尝试使用Mobile Safari在iPhone上播放视频文件时才会出现此问题.上面的代码,ASP.NET Web应用程序托管在IIS 5.1或IIS 6.0上.
有没有其他人经历过这样的事情,并对我能做些什么来获得这个工作有任何想法?
我将用户上传的图像存储在Google App Engine数据存储区中db.Blob,如文档中所建议的那样.然后,我将这些图像提供给/images/<id>.jpg.
服务器总是发送200 OK响应,这意味着浏览器必须多次下载相同的图像(==较慢),并且服务器必须多次发送相同的图像(==更昂贵).
由于大多数图像可能永远不会改变,我希望能够发送304 Not Modified回复.我正在考虑在用户上传时计算图片的某种哈希值,然后使用它来知道用户是否已经拥有此图像(可能将哈希发送为Etag?)
我找到了这个答案和这个答案很好地解释了逻辑,但我有两个问题:
EtagGoogle App Engine?我有一个奇怪的问题,我有一个HttpHandler,其ProcessRequest()事件触发两次.
除了指向静态方法的指针,我在类中没有别的东西,所以我迷失了.
我做了一些谷歌搜索无济于事,甚至认为似乎有一些人有类似的问题:
码:
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
Common.Tracker.TrackPageView(context);
}
Run Code Online (Sandbox Code Playgroud) 在基本情况下,我有要下载的文件和链接按钮来下载他们一个GridView,有什么好处在所有的流媒体这些文件,而不是创建自定义HTTP处理程序简单地从下载链接按钮的事件处理程序的流?
编辑:
正如一些建议的代码重用将有利于处理程序,但在这种特定情况下它不是问题.处理程序也更快,因为它避免了页面生命周期,但是这种轻微的性能提升可能不值得在我的特定情况下创建处理程序.
现在唯一想到的是(假设使用相同的aspx页面方法)在GridView在UpdatePanel中的情况下是否有任何特殊考虑因素?
你怎么看到哪些HttpHandler注册了?如何循环注册的HttpHandlers?我想所有的处理程序都在某个地方,但在哪里.
我试图在Visual Studio中调试HTTP处理程序,并且断点没有被击中.有没有人知道如何在Visual Studio中调试HTTP处理程序?
我在Windows 7计算机上使用VS 2010 Premium,.NET 4.0.在我的Web应用程序中,我在/HTTPHandler/TrackingHandler.cs中有一个HTTP处理程序
以下是我的网络配置文件:
<system.webServer>
<handlers>
<add name="TrackingHandler" path="/tx/*" verb="*" type="ProjectNamespace.TrackingHandler" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
我的HTTP处理程序如下所示
namespace ProjectNamespace
{
public class TrackingHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
//Breakpoint on the very first line below
string tracker = Path.GetFileName(context.Request.PhysicalPath);
.......
}
}
}
Run Code Online (Sandbox Code Playgroud)
我使用内置Web服务器 …
我为ASP.NET MVC4站点编写了一个生成图像的httpHandler.该ProcessRequest函数未被调用.有什么想法吗?
MVC4,IIS Express,Windows 8 Pro
Web.config> system.webServer
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="TextImage" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="TextImage" path="textimage/*.png" verb="*" resourceType="Unspecified" type="MultiStepUI.TextImageHandler, MultiStepUI_MOBETTER" />
</handlers>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
用法
<img src="/textimage/step1.png?q=Step 1&c=404040&w=30&h=250&z=12" />
Run Code Online (Sandbox Code Playgroud) 我已经开发了一个http处理程序来动态地提供图像..
我对每张图片都有相应的最后修改日期.
所以我已经实现了http头缓存,如下所示:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
DateTime lastModified = Convert.ToDateTime("2/1/2013 12:00:00 AM");
string eTag = "test.JPG" + lastModified.ToString();
// set cache info
context.Response.Cache.VaryByHeaders["If-Modified-Since"] = true;
context.Response.Cache.VaryByHeaders["If-None-Match"] = true;
context.Response.Cache.SetLastModified(lastModified);
context.Response.Cache.SetETag(eTag);
//Set cache control header
context.Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
Byte[] imageBytes = CreateImage();
context.Response.OutputStream.Write(imageBytes, 0, imageBytes.Length);
}
Run Code Online (Sandbox Code Playgroud)
注意:这里 将为每个图像动态获取lastModified,每个图像的名称也不同.
响应标题
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: image/jpeg
Last-Modified: Thu, 31 Jan 2013 18:30:00 GMT
Etag: test.JPG2/1/2013 12:00:00 AM
Vary: If-Modified-Since, If-None-Match
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?RTpcTGVhcm5pbmdcQ2FjaGVcR2V0SW1hZ2UuYXNoeA==?= …Run Code Online (Sandbox Code Playgroud) 我有一个MVC4应用程序,我添加了一个HttpHandler:
<system.web>
...
<httpHandlers>
<add path="Files" verb="*" type="MyHttpHandler" />
</httpHandlers>
</system.web>
Run Code Online (Sandbox Code Playgroud)
我也忽略了相关的路径,RegisterRoutes以便MVC不处理对"文件"的请求:
routes.IgnoreRoute("Files/{*pathInfo}");
Run Code Online (Sandbox Code Playgroud)
问题是MyHttpHandler仅针对"文件"的请求调用,而不是针对其任何子文件夹或子文件夹调用.
我已经尝试过使用该<location>元素,但是让它工作就意味着你将在"path"属性中对应用程序的虚拟路径进行硬编码(例如<location path='MyApp\Files'>).
用于允许"文件"及其任何子文件夹(以及这些文件夹的子文件夹等)的所有请求被路由到的正确方法是什么MyHttpHandler?
我正在尝试实现一个IRouteHandler,它返回一个完全实现的IHttpHandler。
因此,当我实现IRouteHandler的唯一一种方法时,我得到了RequestContext参数。
internal class MyRouteHandler : IRouteHandler, IRequiresSessionState
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new MyHandler(requestContext);
}
}
Run Code Online (Sandbox Code Playgroud)
稍后,当请求传入实现的ProcessRequest中的IHttpHandler时:
internal class MyHandler : IHttpHandler, IRequiresSessionState
{
private readonly RequestContext _requestContext;
public MyHandler(RequestContext requestContext)
{
_requestContext = requestContext;
}
public void ProcessRequest(HttpContext context)
{
// How is this HttpContext instance differs from the RequestContext instance?
// Do I need both?
}
}
Run Code Online (Sandbox Code Playgroud)
此HttpContext实例与RequestContext实例有何不同?就我而言,我需要两者吗?(在IRouteHandler实现中,我什么也不做。创建的IHttpHandler将为所有请求提供服务。
httphandler ×10
asp.net ×5
.net ×2
asp.net-mvc ×2
c# ×2
caching ×1
http ×1
http-headers ×1
ihttphandler ×1
iis ×1
iis-express ×1
python ×1
quicktime ×1
video ×1