我想按照這個頁面http://www.deliveron.com/blog/post/SEO-Friendly-Routes-with-ASPnet-MVC.aspx,這是我在Global.asax中,ASP.NET MVC SEO友好的URL
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"MemberRoute", // routeName
"member/{userId}/{pseudoName}", // url
new
{ // url defaults
controller = "Member",
action = "Index",
userId = 0,
pseudoName = UrlParameter.Optional
},
new
{ // url constraints
userId = @"\d+" // must match url {userId}
}
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
MemberController,
public ActionResult Index(int id, string pseudoName)
{
User user;
var unitOfWork = new UnitOfWork();
user = unitOfWork.UserRepository.GetById(id);
var expectedName = user.PseudoName.ToSeoUrl();
var actualName = (pseudoName ?? "").ToLower();
// permanently redirect to the correct URL
if (expectedName != actualName)
return RedirectToActionPermanent("Index", "Member", new { id = user.UserId, pseudoName = expectedName });
return View(user);
}
這是從返回來自AccountController的登錄動作,
return RedirectToAction("Index", "Member", new { id = user.UserId, pseudoName = user.PseudoName });
當重定向發生時,Url最終看起來像http://site.com/Member/1?pseudoName=CEO
我在做什麼錯?
'RedirectToRoute(「Member」,new {id = user.UserId,pseudoName = user.PseudoName})''。查找'RedirectToRoute'。 –
我收到錯誤「在路由集合中找不到名爲'Member'的路由 參數名稱:name」 –