URL Rewriter and IIS configuration
Suppose you want to use http://XXX/aa-bb as your displayed url, but you want to remove the extension from your URL and the actual URL is http://XXX/aa-bb.aspx. You can write some codes by yourself to implement URL Rewriting feature.
But there is a problem. The code only works on dev box. when hosted in production I keep getting 404s error when requesting http://XXX/aa-bb, only http://XXX/aa-bb.aspx can work.
So you got to do some configuration in IIS to solve this problem. Dont't forget that mapping "*all*" requests to asp.net. Here is how-to:
In IIS6, go to home directory tab, click "configuration" and "add a wildcard map to the following file ".
browse to "c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll" and enter .*
ensure that 'check that file exists' is unchecked.
But everything has two sides. It will slow down the performance more or less. secondly, by unchecking "check that file exists" will bring about another problem you will experience. You can not utilize the Error 404 ability provided by IIS to catch error 404 'file not found' to redirect your request to a page you specify.
There is another way to implement URL rewriter. You can use error 404 ability to get the request like "http://XXX/aa-bb" in the aspx page you specify in IIS and then transfer this page to the phisical page you want. But the head status in response for this aspx page will be changed to 404 and the header might be rewrited, which will cause some problems when your websites are required to do SEO since some websites spiders and crawers will ignore error 404 and stop processing this page. Secondly, the css or js defined in the header might reference to wrong link path. I ran into this problem. But actually I don't know exactly what happened inside.
There is one tiny thing we need to notice. When you implement URL rewriter, Suppose you have a displayed URL, Let's say http://XXX/newview/Military", and you want to rewrite it to http://XXX/newview.aspx?Title=Military.
As you can see here, the directory path level is decreased from 2 to 1. So when you use css link like "../css/global.css" you cannot find the css file. So you need to use Resolve("~/Css/global.css") method provided by asp.net.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?