asp.net-mvc - RouteConfig 和带有扩展名的文件名 - MVC5
问题描述
我有以下网址:
/Meetings/doc1.pdf
/Meetings/doc2.pdf
我尝试在我的 RouteConfig 中设置以下内容
var route = routes.MapRoute(
name: "RedirectMeetingDocs",
url: "Meetings/{filename}",
defaults: new { action= "GetAttachmentByName", controller = "Generic" },
constraints: new { filename = @"(.*?)\.(pdf|ppt)" }
);
具有以下功能:
[HttpGet]
public ActionResult GetAttachmentByName(string fileName)
{
...
}
但是,它永远无法正常工作,并且我不断收到 404 错误。
我也试过:
var route = routes.MapRoute(
name: "RedirectMeetingDocs",
url: "Meetings/{filename}.{extension}",
defaults: new { action= "GetAttachmentByName", controller = "Generic" },
constraints: new { filename = new AlphaRouteConstraint(), extension = new AlphaRouteConstraint() }
);
和
public ActionResult GetAttachmentByName(string fileName, string extension)
{
但没有任何效果。
有什么建议吗?
解决方案
好的,我通过在我的 Web.config 中添加以下内容来解决它:
<add name="IATTCRedirectOldMeetingFiles" path="meetings/*" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
现在,上面显示的两个 RouteConfig 都可以工作。
推荐阅读
- python-3.x - 注册后使用 django-allauth 重定向到自定义验证页面
- python - Python 冒泡排序循环问题
- unity3d - SetActive 无法识别?
- javascript - Vue.js / 创建所有选定的按钮不起作用
- c - fprintf() 是否适用于在管道中写入,或者我必须始终使用 write()?
- angular - 设置 Angular Firebase 托管 404 页面
- python - KeyError: 'not found in index' -created dummy variables not found in index
- java - 所有页面中都存在一个图标,如何在不使用重复代码的情况下对其进行编码?
- tensorflow - 有选择地应用示例权重
- arrays - 如何正确插入包含另一个对象的对象的文档