I want to do url mapping using coding in asp.net c#
if /default.aspx page is requested then on client site it should be shown /default.
asp.net(c#) 4.0 .net framework
From Scott Guthrie Article
Mapping URLs using ASP.NET Web Forms
ASP.NET 4.0 now allows you to also use the URL Routing engine to map URLs to ASP.NET Web Forms pages as well as ASP.NET MVC Controllers.
Below is an example of how you can use the new MapPageRoute() helper method in ASP.NET 4.0 to map the /default URL to a default.aspx page that lives immediately under the application root directory:
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute(
"default-page",
"default",
"~default.aspx"
);
}
void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
You may like to check this Url Rewriting with ASP.NET and Managed Fusion URL Rewriter and Reverse Proxy. Also check this example:- An Example of URL Rewriting With ASP.NET
Also check out the Microsoft.AspNet.FriendlyUrls to easily use routing and get friendly urls
Related
Assuming that I have the following ASP.NET website:
http://example.com
I want to expose this url:
http://yourCompany.example.com/yourName
and I want it to route to
{myController}/{myAction}/{yourCompany}&{YourName}
Can I setup a route for this in my RegisterRoutes in RouteConfig class?
You will have to redirect from the http://yourCompany.example.com/[0] to http://example.com/yourCompany/[0] as the subdomains are treated as stand-alone domains.
In my MVC project, There is a Default.html file in root folder and route this file as a default route.
routes.MapRoute(
name: "",
url: "Default.html"
//,
//defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
It's working fine when I access it like http://localhost:51353/Default.html
I host (include this static file) this project in my web server. But it's showing error:
Is there any additional configuration needed to do this ?
If you want to host a static HTML page within an ASP.net MVC project then you need to configure your routing configuration in MVC to ignore requests for those pages.
It worked locally because you may have set it as start page in Visual Studio. For this to work you need to tell MVC to ignore the route if its for the HTML page or ASPX page. Find your routing configuration section, it’s in RouteConfig.cs under the App_Start folder. Use the IgnoreRoute() method to tell Routing to ignore the specific paths.
routes.IgnoreRoute("Default.html"); //ignore the specific HTML page
Now MVC ignores a request to load the Default.html page and leaves IIS to handle the resource.
As per the MVC Routing you cannot map static files to the routing table, because when MVC Routing Machanism provides direct access to physically exist static files.
Able to create Controller and Views on my ASP.NET MVC app.
When I start the application each time I have to type /index.
I read through posts which suggests to use routes.MapRoute(..
But my Global.asax file does not contain route directly.
Do I need to use RouteTable.Routes.MapRoute(.. instead.
In MVC4 the default routes where moved from:
Global.asax
To:
App_Start/RouteConfig.cs
How can I add a routing rule that takes this URL
http://localhost:57334/Blog/index.aspx?Id=23
and converts to this:
http://localhost:57334/Blog/Id/23/blog
Routing rules typically interprets the urls you give and maps them to resources meant to handle those requests. Your url suggests you are using webforms and not asp.net mvc.
What i think you need is URL rewriting... you could check out
this link
Hope this helps
It depends if you are using IIS 6 or 7
If you are using IIS6 you will need to install an add-in and you will need to install something like:
www.isapirewrite.com or www.urlrewriter.net
If you are using IIS7 take a look at http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
I have a web application that I'm using a custom route to route http://domain/MyMVCSite/MyPage.ASP to route to a controller/action of my choosing.
I'm not TOO familiar with custom routing, but as it stands, this is my custom route:
routes.MapRoute(
"Page",
"MyPage.ASP",
new { controller = "KTASP", action = "KTASP", id = "" }
);
As I said, this routes:
http://{domain}/MyMVCSite/MyPage.ASP
I would like for it to route:
http://{domain}/MyPage.ASP
Is this possible? How would I tweak the custom route?
My MVC site is being deployed as a virtual directory of a website on IIS6.
This isn't possible without IIS configuration to rewrite the requests for "http://{domain}/MyPage.ASP" to go to your virtual directory.
Currently, your web application will never get considered, because that page is not within the virtual directory it is mapped to in IIS. You need to either have routes (and a web app) at the root of the web site, or use URL rewriting to forward it to your vdir.