我已经在webforms应用程序中的Global.asax中的RegisterRoutes()中写入了以下内容。 我有一个名为CacheInfo.xml的xml文件,用于存储缓存页面的详细信息。默认页面在xml中有一个名为EnDefaultPage的条目,其中包含两个子节点。 子节点LastUpdationTimeStamp存储默认页面的缓存的最后更新时间戳记(以秒为单位的unix时间戳记)。Asp.net路由不能正常工作
子节点ExpiryTimestamp存储缓存将过期的时间戳。所以如果到期时间戳大于lastupdation时间戳,缓存中的文件将被加载(Default.html)。目前该脚本正在工作,但是它不是路由到Default.html,虽然定义路由的条件块正在执行。我无法找到问题背后的确切原因。任何人都可以给我一个修复建议。所有其他路由都可以正常工作。 我的代码附在下面。
ublic void RegisterRoutes(RouteCollection routes)
{
string relPath = "~/CacheInfo.xml";
string absPath = Server.MapPath(relPath);
XmlDocument xdoc = new XmlDocument();//xml doc used for xml parsing
xdoc.Load(
absPath
);//loading XML in xml doc
string nodeName="", nodeVal="",upStamp="0",expiry="0";
int iUpStamp,iExpiry;
upStamp = xdoc.GetElementsByTagName("EnDefaultPage")[0].SelectSingleNode("LastUpdationTimeStamp").InnerText;
expiry = xdoc.GetElementsByTagName("EnDefaultPage")[0].SelectSingleNode("ExpiryTimeStamp").InnerText;
iUpStamp = Convert.ToInt32(upStamp);
iExpiry = Convert.ToInt32(expiry);
if(!String.IsNullOrEmpty(upStamp)) {
if (iExpiry > iUpStamp)
{
System.Diagnostics.Debug.WriteLine("stamp is " + upStamp + " Expiry is " + expiry);
// routes.MapPageRoute("EnHome1", "", "~/en/DefaultCache.aspx");
routes.MapPageRoute("EHome", "en/", "~/en/Default.html");
//this routing is not working
}
else
{
}
}
routes.MapPageRoute("GArticle", "Gallery/{slug}", "~/Gallery/Article.aspx");
routes.MapPageRoute("GCategory", "Gallery/Categories/{slug}", "~/Gallery/Categories.aspx");
routes.MapPageRoute("GSlideShow", "Gallery/{slug}/{id}", "~/Gallery/SlideShow.aspx");
routes.MapPageRoute("Article", "en/{slug}", "~/english/Article.aspx");
routes.MapPageRoute("Category", "en/Categories/{slug}", "~/english/Categories.aspx");
routes.MapPageRoute("enFeed", "en/category/english/{slug}/feed", "~/en/feed.aspx");
routes.MapPageRoute("teFeed", "te/category/telugu/{slug}/feed", "~/te/feed.aspx");
routes.MapPageRoute("Tags", "en/Tags/{tag}", "~/english/Tags.aspx");
routes.MapPageRoute("tArticleHtml", "te/{slug}.html", "~/telugu/Article.aspx");
routes.MapPageRoute("tArticle", "te/{slug}", "~/telugu/Article.aspx");
routes.MapPageRoute("tCategoryHtml", "te/Categories/{slug}.html", "~/telugu/Categories.aspx");
routes.MapPageRoute("tCategory", "te/Categories/{slug}", "~/telugu/Categories.aspx");
routes.MapPageRoute("tTagsHtml", "te/Tags/{tag}.html", "~/telugu/Tags.aspx");
routes.MapPageRoute("tTags", "te/Tags/{tag}", "~/telugu/Tags.aspx");
}
}
谢谢......但是routes.MapPageRoute(“EHome”,“en /”,“〜/ en/Default.html”)背后的原因是什么?不工作?任何解决方案 – 2015-02-23 18:09:35
这是您的意图吗? 1.启动Web服务器2.确定当前所有过期页面(在启动时)是否转到default.htm。如果你需要逐个案例(现在已过期,而不是开始应用),那么你不能这样做。 RegisterRoutes旨在设置路线的“字典”,可以说是在启动时。它不用于运行时条件逻辑。从开始的角度来看,它很可能是完美的,但是您希望运行时确定。如果你这样做,我会建议看看OutputCache,这在RegsiterRoutes中没有使用。 – 2015-02-23 18:15:57
注意:如果您需要自定义缓存,您仍然无法在RegisterRoutes中为运行时实现它。 – 2015-02-23 18:16:25