使用URLRewrite,部署网站到windows 2003,首页访问不了,其他页面都可以

crazyxu215 2015-08-29 05:34:30
C#写的网站,.net2.0,使用URLRewrite后,首页访问不了
配置IIS的默认首页或者配置规则都不行,首页规则如下:
<RewriterRule>
<LookFor>~/</LookFor>
<SendTo>~/default.aspx</SendTo>
</RewriterRule>

其他页面都访问正常,配置规则如下:
<RewriterRule>
<LookFor>~/([a-zA-Z0-9]+)/</LookFor>
<SendTo>~/123.aspx?p1=$1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/([a-zA-Z0-9]+)/(\d+).html</LookFor>
<SendTo>~/123.aspx?p1=$1&p2=$2</SendTo>
</RewriterRule>

httpHandlers配置如下:
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="*" path="*" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />

如果加上path="*",首页访问不了,报“未将对象引用设置到对象的实例”的错误,找不到页面
如果去掉,首页可以正常访问,这种规则<LookFor>~/([a-zA-Z0-9]+)/</LookFor>的页面访问不了

配置环境是windows server 2003+IIS6 ,希望有高手支招,非常感谢!!!
...全文
170 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
crazyxu215 2015-08-29
  • 打赏
  • 举报
回复
引用 3 楼 shingoscar 的回复:
访问不了是403还是404
应该是报的404错误,URLREWIRTE根本识别不了首页规则,IIS6配置的默认首页也没用 直接把错误结果显示出来的描述如下: 未将对象引用设置到对象的实例。 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。 源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 堆栈跟踪: [NullReferenceException: 未将对象引用设置到对象的实例。] System.Web.HttpContext.RewritePath(VirtualPath filePath, VirtualPath pathInfo, String queryString, Boolean setClientFilePath) +40 System.Web.HttpContext.RewritePath(String filePath, String pathInfo, String queryString) +47 URLRewriter.RewriterUtils.RewriteUrl(HttpContext context, String sendToUrl, String& sendToUrlLessQString, String& filePath) +302 URLRewriter.RewriterFactoryHandler.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +678 System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +175 System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +120 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42
crazyxu215 2015-08-29
  • 打赏
  • 举报
回复
引用 2 楼 starfd 的回复:
<LookFor>~/?$</LookFor> <SendTo>~/default.aspx</SendTo> 改成这样试试
这样改了也没用,还是报一样的错误
Poopaye 2015-08-29
  • 打赏
  • 举报
回复
访问不了是403还是404
  • 打赏
  • 举报
回复
<LookFor>~/?$</LookFor> <SendTo>~/default.aspx</SendTo> 改成这样试试
hwyqy 2015-08-29
  • 打赏
  • 举报
回复
帮楼主顶,我想了很久,也试了下,也没找出原因 也想知道原因了
crazyxu215 2015-08-29
  • 打赏
  • 举报
回复
已经解决了,谢谢各位! 分享方法: 在全局文件里,页面请求最开始,判断原始路径是否为首页。 如果判断是首页,则重写到Default.aspx

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧