微软 URLRewriter重写地址报错:未将对象引用设置到对象的实例。 URLRewriter\RewriterFactoryHandler.cs:行号 38 解决方案

这个错经常在服务器上出现。后来慢慢发现,重启服务器之后一段时间不会报错。但是还是找不到解决办法。最终百度终于找到了问题所在,因为缓存过期了,导致出错。

下载源码,找到报错的地方:

F12进去GetConfig这个方法里面。

	public static RewriterConfiguration GetConfig()
		{
			if (HttpContext.Current.Cache["RewriterConfig"] == null)
				//HttpContext.Current.Cache.Insert("RewriterConfig", ConfigurationSettings.GetConfig("RewriterConfig"));
            HttpContext.Current.Cache.Insert("RewriterConfig", ConfigurationSettings.GetConfig("RewriterConfig"), null, DateTime.Now.AddYears(100), TimeSpan.Zero, CacheItemPriority.High, null);
            return (RewriterConfiguration) HttpContext.Current.Cache["RewriterConfig"];
		}

注释的地方是原来的代码,下面哪一行代码是我修改之后加入缓存时间的代码,把这句代码代替原来的代码重新生成解决方案,将原来的DLL和pdb用重新生成的代替即可。

猜你喜欢

转载自blog.csdn.net/weixin_40068689/article/details/82743934
今日推荐