asp.net mvc 请求路径: 服务器地址/控制器名称/控制器方法名 路由配置:url = controller / action / id
public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } }如下面的是Controller类的Action 例子:
public class IndexController : Controller { // // GET: /Index/ public string Index() { return "HelloMvc"; } public string WebDemo(string name="这是默认参数") { //使用HttpUtility编码来防止恶意插入可执行代码。 name = HttpUtility.HtmlEncode(name); return "<a href='http://www.baidu.com'>"+name+ "</a>"; } }