asp.net-mvc-routing

ControllerActionInvoker

末鹿安然 提交于 2019-12-08 17:30:27
问题 What is the use of ControllerActionInvoker class? 回答1: Basically it's an extensibility point on a Controller class that allows you to get in there and influence how the controller interacts with Parameters, Filters and the Action itself. When a request has been routed to the Controller, the Controller asks the ControllerActionInvoker to deal with the request (which normally involves it calling a method back on the Controller). The main usage of this I've seen so far is to provide dependency

Error with WebApi 2.0 RouteAttribute

社会主义新天地 提交于 2019-12-08 17:19:04
问题 Here's my Global.asax protected void Application_Start() { RegisterRoutes(); } private static void RegisterRoutes() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); GlobalConfiguration.Configure(x => x.MapHttpAttributeRoutes()); GlobalConfiguration.Configuration.EnsureInitialized(); } Here's my Web Api controller [RoutePrefix("api/admin/users/")

Url.RouteUrl returns null

邮差的信 提交于 2019-12-08 17:00:39
问题 I'm buiding a UrlHelper for a route as in best practices the problem is that the returned value is always null when debugging in found that Url.RouteUrl("x") return null Url.RouteCollection["X"] return Route i'm trying to do : public static string Category(this UrlHelper helper, int Id, string category) { return helper.RouteUrl("X", new {id = Id, category= category}); } I can't see where I'm doing something wrong 回答1: It appears that this is being caused because you did not specify a default

Umbraco cannot find the route in backoffice

蓝咒 提交于 2019-12-08 13:41:33
问题 I've used Umbraco 7.3 in my project. I created a custom data type but when I want to call a Surfacecontroller in here is HelloSurfaceController or Hello2SurfaceController , I got an error in umbraco backoffice that said Request error: The URL returned a 404 (not found): I studied some articles about routing but I couldn't solve my problem. I don't know that where I did wrong. How can I solve this problem? Reply.controller.js: angular.module("umbraco") .controller("Reply.controller", function

Can I force MVC to get a new page?

非 Y 不嫁゛ 提交于 2019-12-08 10:50:17
问题 I am using code like this: [OutputCache(Duration = 86400, VaryByParam = "none")] public ActionResult Index() { } Everything works well BUT there are times when I would like to force MVC to get a new page when I do a redirect to the index page using: RedirectToAction("index", "home"); Is this possible? Is there some way that I can invalidate the cache? 回答1: You could try something like: HttpResponse.RemoveOutputCacheItem("/Home"); 来源: https://stackoverflow.com/questions/7404261/can-i-force-mvc

Change route to username after registration

这一生的挚爱 提交于 2019-12-08 10:26:32
问题 I have followed the correct answer marked for this thread How to change route to username after logged in? and my requirement is exactly what the question says. However when I register a new user (I am using username instead of email) the redirection doesn't follow my custom route. For instance, when I register with username = Janet, the URL looks like localhost/?username=Janet and throws an error. But if I manually remove the "/?username=" and keep localhost/Janet then it shows the landing

Running MVC2 Application on IIS 5.2

限于喜欢 提交于 2019-12-08 04:32:14
问题 I recently created an MVC2 application. I am having trouble bringing it up on a Windows 2003 Server running IIS 5.2. My developing machine is Server 2008, so no problems there. Changes I made on Server 2003 is Creating a Wildcard Script Map of * and pointing that to: c:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll I am getting an HTTP 403 Forbidden page. I created a separate apppool and am running that using .Net 4 Here is my global.asax routes.MapRoute( "Default", // Route

Match route relative to path

╄→гoц情女王★ 提交于 2019-12-08 03:30:49
问题 I want any URL that ends with /templates/{filename} to map to a specific controller using either a route attribute i.e. something like: public class TemplateController : Controller { [Route("templates/{templateFilename}")] public ActionResult Index(string templateFilename) { .... } } which works, but the links referencing this route are relative so http://localhost/templates/t1 -- works http://localhost/foo/bar/templates/t2 -- breaks (404) I need something like: [Route("*/templates/

MVC 3 exception: The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc

主宰稳场 提交于 2019-12-08 03:30:36
问题 My application seems to run fine, but I keep getting these exceptions in log4net logs: The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Agency(Int32)' in 'COPSGMIS.Controllers.QuestionController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Not sure whats going wrong? My controller: public ActionResult Agency(int id) { QuestionDAL qd = new

MVC3 Routes with Different Parameter Types

杀马特。学长 韩版系。学妹 提交于 2019-12-08 02:47:55
问题 I am struggling to get my head around routing in MVC3. Previously I have generally just avoided the whole area and stuck with ugly old ?id=1&foo=bar type urls. Not nice. I have 4 routes defined thusly routes.MapRoute("Blog", "{controller}/{action}/{PageNumber}/{PostsPerPage}", new { controller = "blog", action = "list", PageNumber = UrlParameter.Optional, PostsPerPage = UrlParameter.Optional }); routes.MapRoute("Code", "{controller}/{action}/{title}", new { }); routes.MapRoute("Id", "