问题描述
|
这两条路径之间有什么区别?
http://www.mydomain.com/testmvc3
http://www.mydomain.com/testmvc3/
我将代码放在HomeController中:
// GET: /Home/
public ActionResult Index()
{
if (Request.IsAuthenticated)
{
return RedirectToAction(\"Index\",\"Member\");
}
else
{
return View();
}
}
但是只有第二个链接可以正常工作,但是第一个仍然显示主页。(即使它已通过身份验证)如何使它们具有相同的反应?
解决方法
您可能希望在常规路由后加上斜线,否则表明操作中可能包含url参数。
要执行此操作,您可能需要检出MvcCms中的cleanurl过滤器。源代码
private bool IsTrailingSlashDirty(ref string path)
{
//we only want a trailing slash on the homepage
if (path.EndsWith(\"/\") && !path.Equals(\"/\"))
{
path = path.TrimEnd(new char[] { \'/\',\'/\' });
return true;
}
return false;
}
, 我发现了问题,这是由页面缓存引起的。为避免此问题,我将代码修改为:
[OutputCache(Duration = 30,VaryByCustom = \"Request.IsAuthenticated\")]
public ActionResult Index()
{
if (Request.IsAuthenticated)
{
return RedirectToAction(\"Index\",\"Member\");
}
else
{
return View();
}
}
现在可以了。