I am in a situation where I want to restructure my site's urls. That is I have a page that lists the article names (with each article name as a link). As shown below:
ARTICLE1
ARTICLE2
ARTICLE3
Now if I click on an article I want the url to be as follows:
www.domain.com/ArticleID/name-of-the-Article
The term your looking for is "url rewriting" or "routing".
I think the easy way will be to use the ASP.NET MVC routing, it works with Webforms too:
Using Routing With WebForms
Routing with ASP.NET Web Forms
I think you're looking for URL Rewriting, I'd also recomend UrlRewritingNet.
Other possibilities that have worked well:
If your site is hosted on Windows Server 2008, you can use the Microsoft URL Rewrite Module for IIS 7.0.
A nice tool for older servers is Isapi Rewrite (look here - there's a free light version), very similar to Apache style mod_rewrite. May be a problem in shared hosting environments unless the provider is willing to install an Isapi dll.
Related
I've been looking on how to create profile links like in Facebook "www.facebook.com/profile_name"?
Anyone knows how what is the term for that or links for that tutorial in ASP .Net C#?
EDIT:
What I'm trying to achieve here is to create a link for each member that could redirect to their profile page.
Here is an example of the link: www.mywebsite.com/Member_Name
I'm using ASP .Net Framework 3.5
Thanks
I think you're looking for mod_rewrite.
Search the web for apache mod_rewrite or friendly URLS to get up to speed on this topic.
http://en.wikipedia.org/wiki/Rewrite_engine
So it seems you are talking about Url rewriting or routing.
I would suggest using Asp.net Url routing, which is supported Asp.net 3.5 SP1 onward.It's what asp.net mvc uses.
Rewriting:
See this SO answer and this article on the difference between routing and rewriting. (This is to do with IIS/aspnet)
Url Rewrite is at the IIS level, for newer versions of IIS there is a URl rewrite module. See this. For older versions of IIS there is this open source module.
Routing:
Asp.net 3.5 SP1 onward supports routing, which is at the application code level. It can do what you want, something like www.mysite.com/username instead of www.mysite.com/User.aspx?id=1234. See this article and this MSDN article for more info on this.
I heard that in Visual Studio 2010 give built-in functionality for URL rewriting using its URL Routing engine.
I did URL rewriting in earlier version of visual studio by using plug in like intelligencia urlrewrite.
Can any one explain me or guide me to understand that?
Want to implement dynamic and custom url rewriting in my website.
Are you refering to .net 4.0 URL Routing ?
URL routing was a capability we first
introduced with ASP.NET 3.5 SP1, and
which is already used within ASP.NET
MVC applications to expose clean,
SEO-friendly “web 2.0” URLs. URL
routing lets you configure an
application to accept request URLs
that do not map to physical files.
Instead, you can use routing to define
URLs that are semantically meaningful
to users and that can help with
search-engine optimization (SEO).
I want to implement a restful service in ASP.NET. I want it to be compatible with .Net 2.0 and IIS 5+. I am constrained to not use ASP.NET MVC or REST starter kit. By reading on internet I have learned that it can be implemented using HTTPHandlers. The problem is, the request will come in as a POST request. And I want to URL to be like:
http://abc.com/MyService/MyMethod1/
and
http://abc.com/MyService/MyMethod2/
Any workarounds for this?
Thanks,
Vamyip
Your best option is to use URL Rewriting. This is non-trivial in IIS5. The methods I know of are as follows:
Method 1 - ISAPI filter
These are low-level modules that allow you to manipulate the incoming request. Programming one of these is hairy and tough to debug. If you go this route, you are better off using one that has already been built like ISAPI_Rewrite.
Method 2 - IHttpModule
These are managed ASP.Net modules that are easy to add/remove from your application. Again, you are better off using a pre-built component like UrlRewriter.NET. The issue with using one of these, (as BrainLy mentions), is that you have to configure IIS 5 to map all incoming requests to ASP.Net as follows (link):
Open Up IIS and Navigate to the “Home Directory Tab”
Select “Configuration”
Click “Add” and enter “C:\WINNT\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll” in the Executable box. For the file extension, enter “.*”. Finally, make sure that “Check that file exists” is not checked.
One interesting thing to note is that ASP.Net is itself an ISAPI module :)
Once you are able to manipulate URLs using one of these tools, you can easily rewrite the RESTful urls to be handled by your default.aspx page (or whatever handler you choose to use).
If you can allow the restriction of only IIS 7.0 and above you could use URL Rewrite http://www.iis.net/download/URLRewrite to do that pretty easily.
Can I ask why is it that you need to support IIS 5+? That is an 11 year old technology that hopefully people will move out of those platforms in favor of more recent versions. Also keep in mind support for some of those platforms is ending pretty soon.
If the concern is developers running Windows XP I would point out that IIS Express includes version 7.5+ functionality and is available for all platforms Windows XP and above.
I think this will be difficult to do because IIS 5 will not let you handle non ASP.NET file extensions without some additional configuration in IIS. That means you are limited to URLs ending in .aspx etc. To handle URLs like those in your examples you need to map ASP.NET to handle all URLs in IIS, implement some type of URL rewriting, or introduce some kind of hacky 404 redirection.
Once you have the correct mapping in place you can wire up an IHttpHandler, but you will have to parse the incoming request yourself to work out which is /MyService/MyMethod1/ and which is for /MyService/MyMethod2/. If your methods are simple then it is easy to do this with a regular expression.
You should start with a simple handler like this one.
We are interested in adding url rewrite rules programatically from our c#\asp.net 3.5 application to our iis 7.5 web server.
Is there any API for this, or should we just write into the web.config?
Some background: we are developing a hosted CMS that will host multiple websites, each website with it's own custom url rewrites.
This means that we should also be able to handle hundred thousand url rewrite rules - if you are aware of any limitaion of the IIS url rewrite module regarding this - please say so!
important note: we can't use the RewritePath c# method because we are rewriting to different application(seperate dlls with seperate web.config files).
Thanks in advance,
Eytan.
I My Web site on a HELM Control Panel. I developed my web site on MVC.But My Hosting Provider having a Following components installed on That Hosting Account framework 3.5 and IIS6. But I am Unable to Run My site it display me Page not found error.
The problem will be that you're running under IIS6 and if its on shared hosting you're unlikely to have sufficient control to make MVC run without "cheating" a bit.
Under IIS6 requests are only routed to the ASP.NET handlers (I don't promise to get the terminology right) if they have the right extension (.aspx, .asmx, .ashx, etc) with a nice MVC URL there's no extension at all so it doesn't get see by ASP.NET and hence the request won't hit the routing within your MVC app and so you get page not found.
Under IIS7 everything (ish) goes through the ASP.NET handler and so it just works.
So a couple of links to help, here's a stackoverflow question:
ASP.NET MVC on IIS6
and here's Phil Haack on the subject:
http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
Hope this helps.
http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx