URL rewriting in asp.net
开发者_如何转开发i have a web site which will navigate to a different domain once logged in. I need to re write the url by removing the aspx page of the URL and add the domain name from which it navigates to.Also i want to rewrite the URL in an https page which will be redirected from a http page. for eg:-from the site www.xyz.com it has been redirected to www.abc.com.so the url should be displayed as www.abc.com/xyz can anyone can help me on this?
This is commonly done in ASP.NET MVC and this is called ASP.NET Routing. This is applieable in ASP.NET WebForms as well.
You can also use an IIS Module called IIS Rewrite, this is somewhat like Apaches mod_rewrite if you know how that works.
Here is a tutorial on how you get it working.
From MSDN regarding ASP.NET Routing:
In a Web Forms application, you create routes by using the MapPageRoute(String, String, String) method of the RouteCollection class. The MapPageRoute method creates a Route object and adds it to the RouteCollection object. You specify properties for the Route object in parameters that you pass to the MapPageRoute method.
Typically, you add routes in a method that is called from the handler for the Application_Start event in the Global.asax file. This approach makes sure that the routes are available when the application starts. It also enables you to call the method directly when you unit-test the application. If you want to call a method directly when you unit-test the application, the method that registers the routes must be static (Shared in Visual Basic) and must have a RouteCollection parameter.
The following example shows code from a Global.asax file that adds a Route object that defines two URL parameters named action and categoryName. URLs that have the specified pattern are directed to the physical page named Categories.aspx.
This is your Global.asax:
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("",
"Category/{action}/{categoryName}",
"~/categoriespage.aspx");
}
You can use URL rewrite module for that. Some examples are here:
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
精彩评论