好吧,我现在感觉像是一个nincompoop问这个。
我写了一个简单的空白HttpHandler
并在ProcessRequest
方法中添加了一个断点,并在我的web.config中写了这个样板注册标记。
<system.web>
<httpHandlers>
<add path = "*.jpg" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
<add path = "*.jpeg" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
<add path = "*.png" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
<add path = "*.bmp" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
<add path = "*.gif" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
<add path = "*.ico" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
<add path = "*.css" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
<add path = "*.js" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
答案 0 :(得分:1)
我发现了问题。我在我的MVC项目的Views文件夹中的Web.config中创建了条目。显然,我尝试使用我的HttpHandler
投放的资源并不在Views文件夹中。
我将条目移动到项目的根Web.config并开始工作。
答案 1 :(得分:0)
这取决于您运行的Web服务器以及安装的内容。如果右键单击项目和Propeties并选择“Web”选项卡,您将看到“使用Visual Studio开发服务器”或“使用本地IIS服务器”的单选按钮,其中包含IIS Express的复选框(这是项目的默认设置)在我和我的同事机器上。)
如果您使用Visual Studio开发服务器,您的配置应该有效。如果正在使用IIS Express,则需要在不同的位置注册处理程序,并稍微更改属性(删除validate
并添加name
)
<system.webServer>
<handlers>
<add name="StaticJS" path = "*.js" verb = "*" type="AspNetWebFormsApplication.StaticAssetHttpHandler, AspNetWebFormsApplication" />
</handlers>
....
</system.webServer>