asp.net-mvc-routing

ASP.NET MVC Controller Unit Testing - Problem with UrlHelper Extension

核能气质少年 提交于 2019-12-10 00:58:33
问题 Trying to do some controller unit-testing in my ASP.NET MVC 3 web application. My test goes like this: [TestMethod] public void Ensure_CreateReviewHttpPostAction_RedirectsAppropriately() { // Arrange. var newReview = CreateMockReview(); // Act. var result = _controller.Create(newReview) as RedirectResult; // Assert. Assert.IsNotNull(result, "RedirectResult was not returned"); } Pretty simple. Basically testing a [HttpPost] action to ensure it returns a RedirectResult (PRG pattern). I'm not

Custom Routing Rules (e.g. www.app.com/project/35/search/89/edit/89)

北慕城南 提交于 2019-12-09 22:05:47
问题 I would like to create routing rules like the following: www.app.com/project/35/search/89/edit/48 ---> action is edit in the project controller The passed variables should be project# (35), search# (89), and edit#(48) Can someone help me structure a routes.MapRout() for this. I want to use: routes.MapRoute( "Default", "{controller}/{projectid}/search/{searchid}/{action}/{actionid}", new { controller = "Home", action = "Edit", projectid = "", actionid = "" } ); But from previous experience,

How to set Area view as home page in ASP.NET MVC?

谁说胖子不能爱 提交于 2019-12-09 13:31:51
问题 How to setup route for a view to be as home page of a domain in ASP.NET MVC application which contains Areas. I need a view of a particular area to be home page. How could this be done? I tried using the following code without any success. public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( name: "Home", url: "", defaults: new { controller = "Home", action = "Index" }, namespaces: new string[] { "WebApp.Areas.UI.Controllers" } ); } 回答1: In the Area folder there is a

Asp.Net MVC Routing - how do I match the whole URL?

旧巷老猫 提交于 2019-12-09 12:57:16
问题 I'm trying to create a catch-all route to track when an affiliate string is in the URL. An affilite code is marked by an x followed by an int , and will only appear at the end of a URL (but before the query string). The idea is that I will extract the affiliate ID, do some logging, then do a 301 to the same request without the affiliate ID. For example: http://www.domain.com/x32 http://www.domain.com/x32/ http://www.domain.com/path/to/something/x32 http://www.domain.com/x32?query=string http:

asp.net MVC and RESTful routing, rails-style. Is it possible?

耗尽温柔 提交于 2019-12-09 11:13:43
问题 Is there any way to get truly restful routing working in MVC, just like the rails dudes have? I 'm talking about nested urls like /bands/metallica/albums/killemall/track/4 The only library that I found to be useful is Steve Hodgkiss' Restful routing. It seems though a bit risky to base my whole project's routing on this guy's pet-project. What say you MVC veterans? 回答1: Sure: routes.MapRoute("IwannaBeLikeTheCoolRailsKids", "bands/{bandName}/albums/{albumName}/tracks/{trackNumber}", new {

Different websites on different domains, one .NET MVC application?

旧巷老猫 提交于 2019-12-09 07:06:41
问题 Is it possible to have one .NET MVC application, and have it accessible from different domains, in such a way that the content will be domain-dependant? For example, both www(dot)site1(dot)com and www(dot)site2(dot)com will point to my server's IP, and to the same website in IIS. In that website my .NET MVC application will reside. Now, I want the ability to know which site (domain name) triggered the ControllerAction, and act accordingly (for example, display different content for the

Remove Trailing Slash in ASP.NET MVC 4 Route to Application Root

岁酱吖の 提交于 2019-12-09 06:27:36
问题 In my ASP.NET MVC 4 application's RouteConfig file, I have registered the following default route: routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "home", action = "index", id = UrlParameter.Optional }); Now, in my Razor views, I want to generate a URL to my application's root like that: <a href="@Url.Action("index", "home")">Home</a> The generated URL includes a trailing slash; clicking the link thus opens the page localhost/IISApplicationName /. However, I want

How to make one controller the default one when only action specified?

只愿长相守 提交于 2019-12-09 03:49:35
问题 I am using the standard MVC template from MVC 2013. There is a Home controller with actions About, Contact, etc. There is an Account controller with actions Login, Logout, etc. The app is deployed at domain website . The url http://website will produce the output of /Home/Index, without changing the url in the browser address box, ie what the browser shows is not the result of a Http redirect. How do I make the url http://website/X route to /Home/X if X is not another controller in my

How to add extension .html in url asp.net mvc 4?

≯℡__Kan透↙ 提交于 2019-12-09 03:43:33
问题 I have the url: http://localhost:1714/Message/Index I want to show: http://localhost:1714/Message/Index.html How can I do it? 回答1: You need to modify Web.config to map requests for your HTML files to TransferRequestHandler. like so: <system.webServer> ... <handlers> <add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> ... </system.webServer> This is explained here by Jon Galloway.

How can i get the MethodInfo of the controller action that will get called given a request?

孤街浪徒 提交于 2019-12-08 19:15:35
问题 I have a controller and action that's responsible for handling 403s due to the users not being in the correct roles. It has access to the original RequestContext that caused the exception. What I would like to be able to do is decorate my actions with a description of what they do, then allow the user to notify their manager, requesting access including the description in an email. So, how can I work out what action would be called given a RequestContext ? Obviously this is more complicated