asp.net mvc - Set Default Route for a Controller as Index View -
so have url:
www.mywebsite/signup/index
that works fine.
what want add together new route mapping routeconfig class allows next url work:
www.mywebsite/signup
i have tried:
routes.maproute( name: "signup", url: "{controller}/", defaults: new { controller = "signup", action = "index", id = urlparameter.optional }
and:
routes.maproute( name: "signup", url: "{controller}", defaults: new { controller = "signup", action = "index", id = urlparameter.optional }
and:
routes.maproute( name: "signup", url: "{controller}/*", defaults: new { controller = "signup", action = "index", id = urlparameter.optional }
my routeconfig class has been customized , default routing when creating new asp.net mvc project has been changed, looks this:
routes.maproute( name: "defaultconstrained", url: "{controller}/{action}/{id}", defaults: new { action = "index", controller = "home", id = urlparameter.optional }, constraints: new { controller = constrollersascsv() } ); routes.maproute( name: "sitelogin", url: "{site}", defaults: new { controller = "user", action = "login", site = "" }, constraints: new { site = new excludeanduseregex() } ); routes.maproute( name: "default", url: "{controller}/{action}/{id}", defaults: new { controller = "user", action = "login", id = urlparameter.optional } );
where constraint method constrollersascsv (which don't know doing) is:
public static string constrollersascsv(string optional = null) { var list = getcontrollernames(); var sb = new stringbuilder(); sb.append("("); if (!string.isnullorwhitespace(optional)) sb.append(optional); foreach (var cont in list) { if (sb.length > 1) sb.append("|"); sb.append(cont.replace("controller", "")); } sb.append(")"); homecoming sb.tostring(); }
and implementation of getcontrollernames is:
public static list<string> getcontrollernames() { list<string> controllernames = new list<string>(); getsubclasses<controller>().foreach( type => controllernames.add(type.name.tolower())); getsubclasses<apicontroller>().foreach( type => controllernames.add(type.name.tolower())); controllernames.add("elmah"); homecoming controllernames; }
and implementation of getsubclasses is:
private static list<type> getsubclasses<t>() { homecoming assembly.getcallingassembly().gettypes().where( type => type.issubclassof(typeof(t))).tolist(); }
the error getting when going www.mywebsite.com/signup is:
**http error 403.14 - forbidden**
asp.net-mvc asp.net-mvc-4
No comments:
Post a Comment