I am running into an issue where I am trying to implement SEO friendly links in an ASP.Net 3.5 application with IIS6. The issue is that when I try to use a url like "www.text.com/about/" it isn't directed to the ASP.Net pipeline, so I am unable to route the request to the correct physical aspx file. With ISAPI_Rewrite I know I can redirect a request to the specific page, but is there a way to have a request sent to the ASP.Net pipeline, so I can manipulate the request using the built-in routing engine. Any help is appreciated.
Wade
Wade ,
You can either implement urlmodule which extents ihttpmodule.
or you can implement httphandler , You need to make this entry in httphandler section of web.config , so that each request comes to .net handler , you can customize your path there and rewrite the url
let me know if you need any help.
as sample example
http://www.aspnettutorials.com/tutorials/advanced/httphandler-aspnet2-csharp.aspx
let me know if you need any help , i implemented recently
I found the technet article on how to route wildcard traffic to the asp.net pipeline. Here is the link - http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true.
Related
What are the methods and best practices for URL Rewriting (Masking URL) in ASP.NET 4.0?
We have an ASP.NET 4 Website and when testing on the client he wanted to hide or simplify our URL addresses, meaning he wants querystrings and url paths of the server to hide.
How can I achieve something like this in ASP.NET 4 Web Forms?
Thank you.
You can use an IIS module to achieve this
http://www.iis.net/download/urlrewrite
In asp.net 4 u can use Asp.Net Routing.
Please visit MSDN : ASP.NET Routing
Hope it helps. Good Luck.
I'm writing a multi-tenant app that will receive requests like http://www.tenant1.com/content/images/logo.gif and http://www.anothertenant.com/content/images/logo.gif. I want the requests to actually map to the folder location /content/tenant1/images/logo.gif and /content/anothertenant/images/logo.gif
I'm using asp.net Mvc 2 so I'm sure there's probably a way to setup a route to handle this or a custom route handler? Any suggestions?
Thanks!
I created a custom HttpModule that taps into the BeginRequest event and then checks to see what the path is then calles Context.RewritePath
If I understand correctly, because it's URL rerouting, I don't know that MVC 2 routing handles this. You need IIS routing, which varies depending on the version you have. For IIS 6, there is an IIS resource toolkit that can handle these kinds of request, or there is helicontech.com's ISAPI_REWRITE or Ionic's rewriter at iirf.codeplex.com. IIS 7 has an MS add-on for url routing too, from what I hear, as a separate download.
These tools can actually redirect the URL in the ways you want, as MVC doesn't deal with the URL itself for the web site, but the pages within the URL request. the ISAPI_REWRITE and other tools actually redirect requests to hosts as you mentioned.
How to hide/change asp.net page extension from the viewer at the client-side?
I.e. while accessing a page www.xyz.com/Dir/MyPage.aspx, the viewer would only see www.xyz.com/Dir/MyPage.html or www.xyz.com/Dir/MyPage.
You need to look into using URL rewriting. If you are using IIS 7 then you can use Microsoft URL rewrite. I also use the URL rewrite software ISAPI Rewrite. Basically you'll end up creating rewrite rules to append the .aspx extension to the IIS page requests which have no extension. Then all your links created in your code should be created without the .aspx extension.
I realize this response is a bit abbreviated, but I suggest you start learning about URL rewriting.
EDIT: I'm not sure if you'll get this, but I created a screencast and posted it to my blog which covers the basic idea of how to hide the page extension for ASP.NET. I hope it helps :-)
You can use the routing built into MVC. It's not in any way required to only be used with the MVC Framework, and is quite agnostic.
In asp.net 3.5, I'm rewriting the url
http://www.abc.com/archive/1108/harpersdecember
to the following
http://www.abc.com/article.aspx?docId=78
I'm using this code to do it:
Context.RewritePath("/article.aspx?docId=78");
It works fine locally but when I upload to the remote web server, I get a 404 when trying to reference the above page. Any suggestions why it works locally but not remotely?
You may need to create a wildcard mapping in IIS on the remote server so that all requests are processed by ASP.Net. If you do not do this any URLs without .ASPX on the end will not run through your URL rewriting code.
There is a good explanation of this (and other reasons you might use it) on Scott Guthrie's blog.
Not "may" - you definitely need to create a wildcard mapping. Visual Studio uses the cassini web server which essentially passes all requests through .net. IIS only forwards specific mapped requests (by default .aspx, .asmx, etc..) to .net - rewriting a URL in asp.net requires adding a new mapping to get the request to asp.net in the first place
Sounds to me like the production server does not have a default aspx page, ie: default.aspx. If it did, it would reroute the request to your handler.
Easy way to verify this, would be to create a directory and place a default.aspx file in it and try to request it using only the dir name, ie: server.com/newdir/
If that gives you a 404, then you know it for sure.
I was planning to use url routing for a Web Forms application. But, after reading some posts, I am not sure if it is an easy approach.
Is it better to use the URL Rewrite module for web forms? But, it is only for IIS7. Initially, there was some buzz that URL routing is totally decoupled from Asp.Net MVC and it could be used for web forms.
Would love to hear any suggestions..
This is the best article I found about this topic: IIS URL Rewriting and ASP.NET routing by Ruslan Yakushev.
IIS URL Rewriting
When a client makes a request to the Web server for a particular URL, the URL-rewriting component analyzes the requested URL and changes it to a different other URL on the same server. The URL-rewriting component runs very early in the request processing pipeline, so is able to modify the requested URL before the Web server makes a decision about which handler to use for processing the request.
ASP.NET Routing
ASP.NET routing is implemented as a managed-code module that plugs into the IIS request processing pipeline at the Resolve Cache stage (PostResolveRequestCache event) and at the Map Handler stage (PostMapRequestHandler). ASP.NET routing is configured to run for all requests made to the Web application.
Differences between URL rewriting and ASP.NET routing:
URL rewriting is used to manipulate URL paths before the request is handled by the Web server. The URL-rewriting module does not know anything about what handler will eventually process the rewritten URL. In addition, the actual request handler might not know that the URL has been rewritten.
ASP.NET routing is used to dispatch a request to a handler based on the requested URL path. As opposed to URL rewriting, the routing component knows about handlers and selects the handler that should generate a response for the requested URL. You can think of ASP.NET routing as an advanced handler-mapping mechanism.
In addition to these conceptual differences, there are some functional differences between IIS URL rewriting and ASP.NET routing:
The IIS URL-rewrite module can be used with any type of Web application, which includes ASP.NET, PHP, ASP, and static files. ASP.NET routing can be used only with .NET Framework-based Web applications.
The IIS URL-rewrite module works the same way regardless of whether integrated or classic IIS pipeline mode is used for the application pool. For ASP.NET routing, it is preferable to use integrated pipeline mode. ASP.NET routing can work in classic mode, but in that case the application URLs must include file extensions or the application must be configured to use "*" handler mapping in IIS.
The URL-rewrite module can make rewriting decisions based on domain names, HTTP headers, and server variables. By default, ASP.NET routing works only with URL paths and with the HTTP-Method header.
In addition to rewriting, the URL-rewrite module can perform HTTP redirection, issue custom status codes, and abort requests. ASP.NET routing does not perform those tasks.
The URL-rewrite module is not extensible in its current version. ASP.NET routing is fully extensible and customizable.
There's a great post here about the differences between the two from a member of the IIS team.
One caveat I would advise is that for WebForms, you need to be careful when using Routing. I've written a sample implementation of how you'd use routing with WebForms that addresses these concerns and hopefully helps answer your question.
Do you want formatted urls to be a factory for spawning pages?
or do you want to make the .aspx go away?
rewriting, is for making the .aspx go away, or just to tidy up the url.
Routing, is for looking at a request and determining which object should handle it. They sound similar, phil haack has a few good articles on the subject.
in iis6, isapiRewrite, is very good
I recently just wrote my own rewriting system to make the URLs on my sites look better. Basically, you're going to need to write your own IHttpModule and add it to your web.config to intercept incoming requests. You can then use the HttpContext.Current.RewritePath to change what you're pointing at.
You'll also want to configure your site to use the aspnet_isapi for everything.
You'll discover a lot of little problems along the way like trying to work with pages that use "tails" on them (like for PageMethods), or pathing of page elements and form postbacks, but you'll get through them.
If interested, I can post a link to the code and you can check it out. I've worked a lot of the problems out already so you can read through it as you go. I'm sure there are a lot of other people that have done this as well that might be good resources as well.
You may want to check out my answer to this question: ASP.NET - Building your own routing system. I include some good references to help build your own routing system with either using the url rewriting method or the new routing engine that you can use that came out of the ASP.NET MVC project.
The Dynamic Data project that is available with .Net 3.5 SP1 shows a good example of a url routing implementation.
For URL Rewriting on IIS, IIRF works in IIS5, 6, 7. Free. Easy. Fast. Open Source. Regular expression support.