سازگار کردن لینکهای قدیمی یک سایت با ساختار جدید آن در ASP.NET MVC
نویسنده: وحید نصیری
تاریخ: ۱۳۹۱/۰۵/۱۴ ۲۱:۲۴
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
routes.MapRoute(
"old_bloger_tags_list", // Route name
"search/label/{name}", // URL with parameters
new { controller = "Tag", action = "Index", name = UrlParameter.Optional, area = "" } // Parameter defaults
);
routes.MapRoute(
"old_bloger_posts_feeds_list", // Route name
"feeds/posts/default", // URL with parameters
new { controller = "Feed", action = "Posts", name = UrlParameter.Optional, area = "" } // Parameter defaults
);
routes.MapRoute(
"old_bloger_comments_feeds_list", // Route name
"feeds/comments/default", // URL with parameters
new { controller = "Feed", action = "Comments", name = UrlParameter.Optional, area = "" } // Parameter defaults
);
routes.MapRoute(
"old_bloger_post_urls",
"{yyyy}/{mm}/{title}",
new { controller = "Post", action = "OldBloggerLinks" },
new { yyyy = @"\d{4}", mm = @"\d{1,2}" }
);
public virtual ActionResult OldBloggerLinks(int yyyy, int mm, string title)
{
var oldUrl = string.Format(CultureInfo.InvariantCulture, "https://www.dntips.ir/{0}/{1}/{2}", yyyy, mm.ToString("00"), title);
var blogPost = _blogPostsService.FindBlogPost(oldUrl);
if (blogPost != null)
return RedirectToActionPermanent(actionName: ActionNames.Index, controllerName: MVC.Post.Name,
routeValues: new { id = blogPost.Id, name = blogPost.Title.GetPostSlug() });
return this.Redirect("/");
}
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" > routes.MapRoute(
name: "joomla",
url: "fa/index.php",
defaults: new { controller = "Joomla", action = "Index" }
); using System.Web.Mvc;
namespace MVC5Basic.Controllers
{
public class JoomlaController : Controller
{
public ActionResult Index(string option, string view, string id, string itemid)
{
//todo: process parameters and then return something!
return View();
}
}
}