C# - To Implement Routing In .NET MVC
Feb 14, 2011
I'm trying to wrap my mind around the way ASP.NET MVC implements routing.
From what is my current understanding, it seems my route string much have a "{controller}" and "{action}", otherwise it doesn't work?
How would I define the route that using a SearchController and Search action taking both SearchKeywords and SearchCaseSensitive arguments had the following URL?
domain/SearchKeywords/CaseSensitive
Even simpler, how do I map domain to controller SearchController and to Search?
View 3 Replies
Similar Messages:
Jan 14, 2011
We have a shopping cart product. I am trying to implement ASP.Net 4 URL Routing. The problem I have is with image and other resource folders. I can resolve all the links that are defined within the pages and in the code behind. But, some of the links come from html text entered by users.
Using absolute path is not an option. There are some work arounds. But, I want to avoid those work-arounds, because we don't want to burden the users. Is there a way to achieve this through URL Routing?
E.g. The image path derived from the rewritten page: [URL]
Is there a way to achieve this without any patch work?
View 2 Replies
Apr 20, 2013
i want to avoid displaying page as [URL] It should show as [URL]....
View 1 Replies
Apr 2, 2010
Is it advisable to implement url routing for an asp.net(webforms) website which is one year old... What are the factors to be considered before implementing....
Edit: It is a web based product website developed my company and users should pay for using it...
View 2 Replies
Oct 31, 2010
I need to implement Routing or Url-Rewriting in my application. So, is there any utility like logging utility Elmah. I dont want to write much code, I need to configure and start playing.
View 2 Replies
Jun 19, 2010
I am using ASP.NET 4.0 Web Forms. I learned that, in order to optimize my Web Application for Search Engine, I must implement custom 404 page. But the way Microsoft tell us to implement custom 404 (within Web.Config file), that is not good for SEO. Microsoft says,
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="404" redirect="Page-Not-Found.aspx" />
</customErrors>
But when the page is not found, IIS issue 302 redirect to Page-Not-Found.aspx page which is not good. So, I implemented custom 404 page using Routing technique that is available in ASP.NET 3.5 SP1 and 4.0. I used the following router in Global.asax page
View 2 Replies
Feb 10, 2010
Many hosting companies let you define which page will be shown to the user if the user goes to a page that does not exist. If you define some .aspx page then it will execute and be shown.
My question is, why not use this for routing. since I can parse the users URL and then do a server.transfer to the page I want. I checked and there is no redirect sent to the client and the http headers are HTTP/1.1 200 OK.
So, is this a good idea for servers that don't have ASP.NET 3.5 SP1 or if you are not using MVC?
View 1 Replies
Jul 20, 2010
I tried everything I could find, but still does not work on IIS routing.
View 2 Replies
Dec 12, 2010
I am using:
ASP.NET 3.5 SP1 with Web Forms Routing thru Global.asax (System.Web.Routing and RegisterRoutes)IIS 7
Everything is working fine in my local machine, but it gives the following error in my hosting environment:
Could not load file or assembly 'System.Web.Routing, Version=3.5.0.0, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I did everything inside my web.config file mentioned in the following link:
[URL]
But I am still getting the above error.
What else am I supposed to do fix the error?
View 1 Replies
Feb 22, 2011
I have a Web application where i have added a reference to a RESTful WCF. I got the WCF url Routing to work in my webapplication by adding Inherits="RestService.Global" to the Web applications Global.asax.
<%@ Application Codebehind="Global.asax.cs" Inherits="RestService.Global" Language="C#" %>
But then i tried to create url Routing for the Web application and it does not work with the Inherits="RestService.Global" in the Global.asax. If i take it away it works fine. Is there a correct way to do this.
View 1 Replies
Jan 31, 2011
I'm trying to create my own CMS and I've gotten a little bit stuck at the stage of URL routing.
I want clean URLs without extensions and I'd like to be able to create and modify them in a web based interface without any messing around with IIS or actual files.
I've seen how to create a static route, but for that I need to go into my Global.asax file and manually add it.I would like to have all of these routes stored in a database so that I can easily modify them later.
Does anyone know how this can be achieved?
Just for extra information, I will be attempting to create a feature so that if a path exists, but is later changed, a 301 redirect is created to the new URL, is this also possible? (My first problem is the main issue, but thought I might ask this as well just in case it makes a difference)
View 2 Replies
Sep 2, 2010
How to handle asp.net mvc routing along with asp.net webform routing. I have merged my mvc app into my existing web application. In my web application i have implement routing as below:
routes.Add("View Product Details", new Route("Product/{City}/{Manufacturer}/{Name}/{ProductID}/{*ProductType}"));
Similarly i have implemented routing in mvc as below
routes.MapRoute("Product Details",
"Product/{City}/{Manufacturer}/{Name}/{ProductID}/{ProductType}",
new
{
controller = "Home",
action = "ProductDetails",
City= UrlParameter.Optional,
Manufacturer= UrlParameter.Optional,
Name= UrlParameter.Optional,
ProductID= UrlParameter.Optional,
ProductType= UrlParameter.Optional
});
How to handle both pages, as one is custom web form while other is asp.net mvc view?
View 1 Replies
Nov 30, 2010
Response.RedirectPermanent(Url); can redirect permanently to a url.
However, during my SEO process, I decided to change my routhing rule.
For example,
I change "/tag/{tag}-quotes" routing rule to "quoes-about/{tag}", but I don't want to lose all the traffic to old routing url.
What is the best way to handle this permanent redirection?
View 4 Replies
Jul 12, 2010
I consider the following an error, and not a feature:
When posting a request, any parameters are held in the HttpContext.Request.Form as key/value pairs. This is perfectly fine for the recipient of the request. Unfortunately, however, further down the chain these values still exist and take precedent in binding over new parameters created during processing.
This is obvious in the RenderAction scenario. If a new parameter is created in a view and passed through RenderAction, if the parameter has the same name as one of the initial request parameters (or a form field for that matter), then MVC Binding will bind the initial request form value to the Action being called, and not the new parameter being defined in the RenderAction call. What's even more frustrating, is there is no easy way to override the initial form values.
It really does not make sense that a value defined in one context, should live throughout the entire processing context... at least without the developer being able to determine it should remain. At a minimum, any new parameter defined in the process with the same name should either a) be received as a parameter and not a form value; or b) override the form value.
View 5 Replies
Nov 3, 2010
I'm currently using URL Rewriting, but I recently stumbled upon this link on Rerouting, and it looks like it's quite simple yet powerful, and easier to implement than URL Rewriting, a "downside" probably is that configurations are not sitting on a web.config file but rather on the code itself, but I was wondering about the differences, and advantages of using one over the other. Having read some resources about routing, I can see the differences, and now I reformulate my question:
Is it worth it to move from URL Rewriting to Routing?
Are there any IIS-specific configurations that should be made?
Is it recommended to use it on a ASP.NET WebForms Application, or is it oriented to other kind of projects?
View 1 Replies
Feb 22, 2010
I've been doing research for a few days now and I know that I want to do ASP Routing over Rewriting. I found this great article:http://www.4guysfromrolla.com/articles/051309-1.aspx and also
http://blogs.msdn.com/mikeormond/archive/2008/05/14/using-asp-net-routing-independent-of-mvc.aspx. I write in VB.NET, these two articles are written in C#. I converted the code, but I must be missing something because my routing doesn't work correctly.
I was able to download the code from 4guys and it works fine. I found some differences between my results and theirs when I stepped through error checking. I added the 3 lines to the web.config file:
<system.web>
<httpModules>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0,[code]....
I right clicked on my project and added a reference to the System.Web.Routing dll.I created a Global.asax file in the root directory.
<%@ Application Language="VB" %>
<%@ Import Namespace="System.Web.Routing" %>
<script runat="server"> [code]....
Theirs shows the correct value of whatever you click on The requestContext variable, > HttpContext > System.Web.HttpContextWrapper > Request > System.Web.HttpRequestWrapper > PhysicalPath = "C:UsersNvXDesktopMyWebsiteWebResource.axd"
Theirs shows PhysicalPath = "C:\Users\NvX\Desktop\RoutingDemo\Products\Pavlova" (Pavlova was the link I clicked on)
When I query the database using LINQ, it never finds WebResource.axd and redirects to the NotFound.aspx page. When I load Default.aspx, I want it to load that page. If I type /tjnevis (which is a username in the database), I want it to go to a page where I can put together a profile, pulling the information for that username, which I can figure out. It's the routing that I'm having trouble with. If I could get it to work correctly, I think the PhysicalPath should look similar to the 4guys example I downloaded.
View 4 Replies
Aug 6, 2010
I have an ASP.NET MVC app and I have a WebForm page I built in the MVC due to a tutorial on how to do something I needed to do, but it was all in WebForm style. Ive tried to figure out how to do the same thing in MVC format but cant figure it out. So I was needing to figure out how to use this page in my MVC app. But when I try to go to the page, it gives me the error "Page cannot be derived from ViewMasterPage unless Page derives from ViewPage." So I had to make a new standard MasterPage also.
The situation is this. I have a search bar located in the MVC ViewMasterPage thats on every page that is derived from it. Once a user submits info in the search bar, it calls the WebForm Search.aspx page and displays the results on the Search.aspx page. I want the URL to be like "http:///search//. The Search.aspx page is located in the root of the project. How would I get the results Im looking for?
View 1 Replies
Nov 2, 2010
I have a url which will take the following form:
/AuditReview/Review/15d49a66-5c11-492c-921f-9e1700bd2618
I cannot get this to route, my routes look like this:
MvcRoute.MappUrl("{controller}.mvc.aspx/{action}/{auditEventUid}")
.WithDefaults(new {controller = "AuditReview", action = "Review"})
.WithConstraints(new { controller = "AuditReview", action ="Review", auditEventUid = new GuidConstraint() });
MvcRoute.MappUrl("admin/{controller}.mvc.aspx/{action}")
.WithDefaults(new { controller = "audit", action = "index" })
.WithConstraints(new{controller = "audit"})
.AddWithName("admin", routes);
MvcRoute.MappUrl("{controller}.mvc.aspx/{action}")
.WithDefaults(new {action = "Index"})
.AddWithName("Default", routes);
View 2 Replies
Feb 21, 2011
I used to build my web apps in asp.net in such there is only one page witch is default.aspx
http://localhost/mywebapp1/?q=blog/posts/get/42
I do parse 'q' by myself and do all processing. I don't really need to all MVC staff. I just want to remove "?q="
View 2 Replies
Aug 6, 2010
This is more of an ASP.NET Routing question than MVC, so I will gladly move this post to another forum if prompted!
I am using ASP.NET Routing without using MVC.
I am trying to implement the following URLs:
[URL]
[URL]
[URL]
Each page can have sub-pages:
[URL]
or even sub-sub-pages:
[URL]
I am currently implementing this as follows:
1) GLOBAL.ASAX
[Code]....
2) ROUTE HANDLER CLASSES
[Code]....
View 2 Replies
May 19, 2010
i'm new to routing in aspnet mvc.. i have following code:
[code]....
when i enter "localhost/school" in addressbar, it is giving 404 error instead it should route to my "schoolIndex" action
i have given route-name as "School" where it is used ?
View 1 Replies
Apr 30, 2010
I am working on a website in asp.net mvc. I have a route
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
ew { controller = "Home", action = "Index", id = UrlParameter.Optional }
View 4 Replies
May 7, 2010
I am using MVC 2.0 to create my application,my problem i s related to the routing. Actually in my application each user have required seperate subdomain,like
www.example.com/user1/ ,www.example.com/user2/ ...etc.the default domain is www.example.com.So how can i make it possible with routing in mvc.
i have tried like this,
routes.Add(new Route("{id}", new RouteValueDictionary(new { controller = "User", action = "login", id = " " }), new MvcRouteHandler()));
var defaults = new RouteValueDictionary(
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
routes.Add(new Route("{controller}/{action}/{id}", defaults, new MvcRouteHandler()));
But the problem is that it take deafult (www.example.com) directly to user login page.I want the default page as Home/index and when www.example.com/user1/ it will go to user login page.
View 1 Replies
Oct 14, 2010
I'm working with a client that wants the URLs in our web application to be in French. I'm an English developer and we also have English clients. This is an interesting problem is there something int the ASP.NET MVC Framework that would enable me to do this?
Here's the scenario. The route...
Specific EXAMPLE English URL
www.stackoverflow.com/questions/ask
So in MVC my Area, Controller and Actions all need to have both English and French translations.Obviously maintainability would be a HUGE issue if I were to go and hardcode all my Controllers, Views and Action names to French. Is there anyway to localize the route that is presented in the browser without doing this? Keeping in mind there are lots of different routes in the application. A couple Areas each with a handful of Controller each with many Actions?
Note this message is also on SO: http://stackoverflow.com/questions/3935768/is-it-possible-to-localize-a-url-routing-in-asp-net-mvc
View 3 Replies
Aug 30, 2010
I'm using IIS 7 with Windows Server 2008 and the app doesn't even run when I open it up on localhost. May be because I transfered the app file from Windows Server 2000?
View 6 Replies