asp.net route mapping for web pages - asp.net

I need to implement route mapping in asp.net web application. there are many tutorials telling how to do it in mvc. but i need to do it in web pages.
I have done it successfully for parent domain. my website also handles fake domain(wild card dns) as well, I need to map routes for subdomains as well.
http://mysite.com/login is mapped to http://mysite.com/default.aspx
but , now i want to map http://login.mysite.com to http://login.mysite.com/login.aspx
and http://signup.mysite.com/ to http://signup.mysite.com/signup.aspx
any idea how to do it?

Are you sure you need routing for this? It seems your just want redirection which can be handled by IIS or web.config.
If you really need routing, there are plenty of articles on both MVC as well as web forms, just search. In MVC you do it using the RouteConfig.cs file and in web forms you do it via Global.asax.cs file (or some helper referenced from global.asax.cs). Basically in web forms you add your routes to the RouteTable.Routes collection.
The code will look something like this (untested):
routes.MapPageRoute("",
"login",
"~/default.aspx");
Here are a couple of links which can get you started on routing:
Walkthrough: Using ASP.NET Routing in a Web Forms Application
RouteTable.Routes Property

Related

Hiding http file extension without using MVC controller

I am using basic asp.net web application project template, because I want to move away from MVC into SPA.
Most of my pages will just be basic html files that will interact with the server through ajax calls. That said I want to hide the .html extension, but I don't want to create controllers just to hide this, which is too much of an overkill.
Of another note, I am using Azure as well, so setting this up on IIS directly is not going to work, as I would not be able to scale the administration nicely.
So how can I hide the html extensions without such a heavy layer as an MVC controller?
This sounds like a job for Url Routing
Url Routing allows you to intercept a request and then determine how to service it. It is how MVC does it and has many other useful benefits. If the router isn't able to service it, it falls back to the default ASP.NET pipeline processing, and then IIS.

Remove ASP.NET MVC URL routing from project

This is a similar question to
"How To Disable ASP.NET MVC Url routing" which hasn't been answered (I don't think the responders understood why it was needed).
I have an existing application that uses AngularJS and MVC url routing to serve the templates. I want to remove the MVC url routing as it is redundant (see comment below. we are using webApi to return data via ajax so the views/controllers are not needed).
I have removed the call to RegisterRoutes in the Global.asax.cs. There doesn't seem to be anything in the Web.config apart from a reference to System.Web.Routing so I left it.
I am using IIS Express with Visual Studio 2012.
When the application runs I get a 403.14 Forbidden error. I have enabled directory browsing. I have set the start page in the project in Visual Studio but I get a 404 despite the file definitely being there.
I have tried creating a non-mvc website and copying the contents of the web.config to my application, but this didn't work.
if you mean by removing the .aspx on the end (www.something/home.aspx);
In C#, instead of using
response.redirect("~/home.aspx");
use
server.transfer("~/home.aspx");
AngularJs routing has nothing to do with ASP.Net MVC Routing.
Angular Routing:
Is used for deep-linking URLs to controllers and views (HTML
partials). It watches $location.url() and tries to map the path to an
existing route definition.
ASP.Net MVC Routing:
ASP.NET routing enables you to use URLs that do not have to map to
specific files in a Web site. Because the URL does not have to map to
a file, you can use URLs that are descriptive of the user's action and
therefore are more easily understood by users.
In essence, AngularJs routing deals with client-side routing (using the location Url), whilst ASP.Net MVC deals with mapping http Urls to the appropriate controller/action in the server-side.

Asp.net url routing in application having more than one page

I am using URL routing to make links to users profiles in asp.net, its work but the rest pages of the application not work , did i have to define a route for all pages or i miss something in somewhere.
I don't work with asp.net mvc but with asp.net web forms.
For profile page i want the routing but there is pages i just wont to use a asp x link to it
but all the pages now have the same URL defined in the routes in the global file.
I write this problem before two days always i have a problem.
You can debug your routes with ASP.NET MVC Routing Debugger Visualizer
or take a look at the blog of Phil Haack

Use System.Web.Mvc in non MVC ASP.NET Web Forms Application

We are developing an ASP.NET Web Forms application with REST modelled URL, for which we are using Route tables in global.asax. However, recently we came over a problem where the WebResource.axd and ScriptResource.axd files were getting routed as well. We wanted to use the RouteCollection.IgnoreRoute function. However, since it in System.Web.Mvc, it would mean that we would need to reference that dll in a non MVC Web Forms application.
Is it safe for us to continue with the approach. If anyone has a better way to ignore routes from within the Web Forms application please do share. Please also note that the application has been extensively developed in Web Forms and moving to MVC at the current stage is not feasible.
For web forms you need to use System.Web.Routing
Put this is Global.asax
void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
routes.Ignore("{resource}.axd/{*pathInfo}");
routes.MapPageRoute(
"Home", // Route name
"WWWWWW", // Route URL
"~/Default.aspx" // Web page to handle route
);
}
Did you know you could safely run an ASP.NET Web Forms and MVC application combined? Here are some links:
http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx
http://www.packtpub.com/article/mixing-aspnet-webforms-and-aspnet-mvc
Also, you can just use URL routing in ASP.NET 4 applications, as Registered User pointed out above. Read more about it here: http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx

Integration ASP.NET web forms blogging framework into ASP.NET MVC

Is there any way to use something like BlogEngine.NET (a blogging framework developed on the ASP.NET web forms model) in an ASP.NET MVC application? I want something where I can simply go to http://rooturl/blog and have it fire up the BlogEngine.NET site. I'm assuming that the ASP.NET MVC framework will intercept this call however and try to route it to the "BlogController"'s Index function though. Is there any way around this or is this a non-issue?
Scott Hanselman wrote on this a while back:
Plug-In Hybrids: ASP.NET WebForms and ASP.MVC and ASP.NET Dynamic Data Side By Side
But if I recall correctly, if you don't have a controller that matches /blog then the engine will default to sending the request to your /blog folder, and away you go, on top of that, as Scott notes:
Why doesn't ASP.NET MVC grab the request? Two reasons. First, there's an option on RouteCollection called RouteExistingFiles. It's set to false by default which causes ASP.NET MVC to automatically skip routing when a file exists on disk.
However, he goes on to note that you could just add the following at the top of your route definitions:
routes.IgnoreRoute("blog/{*pathInfo}");
Which would then ignore all requests to /blog/

Resources