ASP.NET MVC 路由 - 向路由添加 .html 扩展名 [英] ASP.NET MVC Routing - add .html extension to routes

查看:45
本文介绍了ASP.NET MVC 路由 - 向路由添加 .html 扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 MVC 和路由很陌生,我被要求修改一个应用程序以使用不同的 url.由于我没有经验,所以对我来说有点过头了.

i am pretty new to MVC and Routing and i was asked to modify an app to use diffrent url's. a task that is a bit over me since i have no experience.

好的,让我们谈谈一些代码:

ok, lets talk a bit of code:

routes.MapRoute(
"CategoryBySeName", // Route name
"products/{SeName}", // URL with parameters
new { controller = "Catalog", action = "CategoryBySeName" }
);

这按预期工作,但是客户端想要路径末尾的.html",所以我改变了:

this works as expected, but then the client wanted ".html" at the end of paths, so i changed:

"products/{SeName}", // URL with parameters

到:

"products/{SeName}.html", // URL with parameters

失败(IIS 404 页面 - MapRequestHandler)似乎 iis 正在尝试加载具有该名称的物理文件,而不是将其传递给应用程序.

which fails ( IIS 404 page - MapRequestHandler) it seems like iis is trying to load a physical file with that name instead of passing it to the application.

类似:ASP.NET MVC 路由从 html 开始页(未回答,不重复)

Similar: ASP.NET MVC Routing to start at html page (not answered, Not duplicate)

推荐答案

您猜测 IIS 处理程序可能在 MVC 可能正确之前获取请求.

You're guess that an IIS handler is probably grabbing the request prior to MVC is likely correct.

假设 IIS 7:http://technet.microsoft.com/en-us/library/cc770990(v=ws.10).aspx

您需要在 IIS 中编辑 .html 处理程序才能使用 ASP.NET.

You need to edit the .html handler in IIS to use ASP.NET.

您可以在 II6 映射部分的应用配置中的主目录选项卡下的网站属性中找到它.

You can find it in the website properties under the home directory tab in app configuration in the mappings section in II6.

类似(版本可能不同)的内容:C:windowsmicrosoft.netframeworkv4.0.30319aspnet_isapi.dll 是处理 .html 文件所需的.

Something along the lines of (version may be different): C:windowsmicrosoft.netframeworkv4.0.30319aspnet_isapi.dll is what you need to handle the .html files.

这篇关于ASP.NET MVC 路由 - 向路由添加 .html 扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆