Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

c# - ASP.NET MVC Routing - add .html extension to routes

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" }
);

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

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

to:

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

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...