I have a project that serves some blog data and pictures. I created controllers and also actions for both blog and pictures.
I updated Global.asax.cs to create user friendly urls. No problem till here.
Now I want to add a simple controller which is Comment and an action which is AddComment.
When I did this usual operations, and tried to access MyProject/Comment/AddComment; it returns 404 not found error.
How should I update my global.asax.cs for adding comment?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace PersonalApp
{
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{type}/{id}",
new { controller = "Blog", action = "Index", id = UrlParameter.Optional, type = UrlParameter.Optional }
);
routes.MapRoute(
"BlogFix",
"{controller}/{action}/{id}",
new { controller = "Blog", action = "Index", ad = UrlParameter.Optional }
);
routes.MapRoute(
"ArticleWithoutAction",
"{controller}/{gelenId}/{title}/{date}",
new
{
controller = "Blog",
action = "ReadMore",
gelenId = UrlParameter.Optional,
title = UrlParameter.Optional,
date = UrlParameter.Optional
}
);
routes.MapRoute(
"ArticleWithAction",
"{controller}/{action}/{gelenId}/{title}/{date}",
new
{
controller = "Blog",
action = "ReadMore",
gelenId = UrlParameter.Optional,
title = UrlParameter.Optional,
date = UrlParameter.Optional
}
);
routes.MapRoute(
"DefaultB",
"{controller}/{action}",
new
{
controller = "Blog",
action = "ReadMore"
}
);
routes.MapRoute(
"DefaultOfImage",
"{controller}/{type}/{id}",
new { controller = "Image", action = "Index", id = UrlParameter.Optional, type = UrlParameter.Optional }
);
routes.MapRoute(
"ImageFix",
"{controller}/{action}/{id}",
new { controller = "Image", action = "Index", ad = UrlParameter.Optional }
);
routes.MapRoute(
"ImageWithoutAction",
"{controller}/{gelenId}/{title}/{date}",
new
{
controller = "Image",
action = "Show",
gelenId = UrlParameter.Optional,
title = UrlParameter.Optional,
date = UrlParameter.Optional
}
);
routes.MapRoute(
"ImageWithAction",
"{controller}/{action}/{gelenId}/{title}/{date}",
new
{
controller = "Image",
action = "Show",
gelenId = UrlParameter.Optional,
title = UrlParameter.Optional,
date = UrlParameter.Optional
}
);
routes.MapRoute(
"DefaultImage2",
"{controller}/{action}",
new
{
controller = "Image",
action = "Show"
}
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
}
Thanks.