UrlRewrite em ASP.NET 2.0

by Felipe Lambert 10. February 2010 09:03

Para quem que assim como eu, fui "obrigado" a desenvolver a aplicação em 2.0 e um dos requisitos era a url amigável

seguindo um tweet do @RamonDuraes

O componente responde pelo namespace UrlRewritingNet.UrlRewrite, desenvolvido em código aberto pode ser encontrado em  http://www.urlrewriting.net/149/en/home.html possui o download da documentação, binários, exemplo e fonte,

fazendo uso de configurações no webConfig, e possivel reescrever a url exibida para o usuário e realmente acessar outra url no servidor, assim uma url de servidor com querystring como http://www.urlrewriting.net/149/en/home.html facilmente é transformada em: http://www.urlrewriting.net/149/en/home.html.

Várias soluções para reescrever urls com o ASP.NET possui disvantagens, como perder o suporte a Themes e Master Pages, alem de precisar de direitos de Administrador para instalar a Extensão ISAPI no servidor.

Mas nem tudo é maravilha, você so pode reescrever requisições tratadas pelo ISAP no servidor, ou seja extensões .aspx, para outras extensões deve ser feita uma configuração adicional no IIS ISAP. (disponivel na pagina 14 da documentação), pelo mesmo motivo pode não ser possivel a url sem extensão (faça um teste, aqui funcionou), e requests crossPage (este não funcionou... só com segurança desabilitada =/).

O navegador pode se perder com as imagens e a url da página, sendo necessária a inclusão do root "~" e runat="server" nas imagens conforme <image src=“~/images/pictures.gif“ runat=“server“/>

 

A configuração do urlRewrite é feita no webconfig adcionando o codigo abaixo

 <add name="Rule1"  virtualUrl="^~/(.*)/Detail(.*).aspx"            
           rewriteUrlParameter="ExcludeFromClientQueryString" 
           destinationUrl="~/Default.aspx?language=$1&amp;id=$2"
           ignoreCase="true" />

Onde a virutalUrl é a url a ser redirecionada para a destinationUrl sendo facil identificar o (.*) da expressão regular sendo pasado para o $1 da segunda expressão regular em destinationUrl.

A documentação consta os demais parametros possíveis de serem utilizados.

 

Comments

2/10/2010 11:07:45 PM #

A certas coisas na vida que valem a pena quando quando se faz "obrigado".

FabioH2C Brazil

6/5/2010 1:00:25 AM #

An intresting editorial, can I ask what blog you are using? I have been looking for a good theme for quite a while now.

vertu phone United States

6/6/2010 10:58:05 PM #

I love travelling so much that I often surfing on many journey  forum to learn knowledge about trip, and I think this forum is the best, from where I got the newest information about journey. Here I want recommend some excellent websites www. ripe8.net, There are many good products help you make a good journey.

adidas 35th anniversary shoes People's Republic of China

6/28/2010 5:04:06 PM #

Thanks so much for this.  I've been looking all over for something like this.

trade forex United States

7/23/2010 4:33:00 AM #

Thanks so much for posting these, they are fantastic! So bummed I missed what looks like a truly unique evening.
http://www.nikeairjordan.cc/air-jordan-6-vi-20/

jordans 6 Sweden

7/27/2010 8:55:13 AM #

Displaying more complex media (vector graphics, animations, videos, sounds) requires plug-ins such as Adobe Flash, QuickTime, Java run-time environment, etc. Plug-ins are also embedded into web page by using HTML/XHTML tags.

web design company United States

7/27/2010 8:55:38 AM #

Displaying more complex media (vector graphics, animations, videos, sounds) requires plug-ins such as Adobe Flash, QuickTime, Java run-time environment, etc. Plug-ins are also embedded into web page by using HTML/XHTML tags.

web design company United States

7/27/2010 8:55:49 AM #

Displaying more complex media (vector graphics, animations, videos, sounds) requires plug-ins such as Adobe Flash, QuickTime, Java run-time environment, etc. Plug-ins are also embedded into web page by using HTML/XHTML tags.

web design company United States

7/27/2010 8:56:01 AM #

Displaying more complex media (vector graphics, animations, videos, sounds) requires plug-ins such as Adobe Flash, QuickTime, Java run-time environment, etc. Plug-ins are also embedded into web page by using HTML/XHTML tags.

web design company United States

7/28/2010 3:13:15 AM #

ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites, web applications and web services

business expansion United States

7/28/2010 3:13:30 AM #

ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites, web applications and web services

business expansion United States

7/29/2010 10:34:25 PM #

<a href="www.mbtzapatos2010.com"><strong>Mbt zapatos</strong></a> olvidar cómo empezó, tal vez –<a href="...mbt-zapatos-2010.com"><strong>Mbt zapatos</strong></a> Cheng Zhaofeng migrando hacia el cielo azul, no importa dónde son soleados<a href="...mbt-zapatos-2010.com"><strong>Mbt zapatos</strong></a> es la más hermosa en mis ojos, cada sonrisa, me hacen borracho.

xia People's Republic of China

7/29/2010 10:35:11 PM #

<a href="www.mbtzapatos2010.com"><strong>Mbt zapatos</strong></a> olvidar cómo empezó, tal vez –<a href="...mbt-zapatos-2010.com"><strong>Mbt zapatos</strong></a> Cheng Zhaofeng migrando hacia el cielo azul, no importa dónde son soleados<a href="...mbt-zapatos-2010.com"><strong>Mbt zapatos</strong></a> es la más hermosa en mis ojos, cada sonrisa, me hacen borracho.

xia People's Republic of China

7/29/2010 10:35:30 PM #

<a href="www.mbtzapatos2010.com"><strong>Mbt zapatos</strong></a> olvidar cómo empezó, tal vez –<a href="...mbt-zapatos-2010.com"><strong>Mbt zapatos</strong></a> Cheng Zhaofeng migrando hacia el cielo azul, no importa dónde son soleados<a href="...mbt-zapatos-2010.com"><strong>Mbt zapatos</strong></a> es la más hermosa en mis ojos, cada sonrisa, me hacen borracho.

xia People's Republic of China

7/29/2010 10:35:50 PM #

<a href="www.mbtzapatos2010.com"><strong>Mbt zapatos</strong></a> olvidar cómo empezó, tal vez –<a href="...mbt-zapatos-2010.com"><strong>Mbt zapatos</strong></a> Cheng Zhaofeng migrando hacia el cielo azul, no importa dónde son soleados<a href="...mbt-zapatos-2010.com"><strong>Mbt zapatos</strong></a> es la más hermosa en mis ojos, cada sonrisa, me hacen borracho.

xia People's Republic of China

8/3/2010 9:17:00 PM #

It was a beneficial workout for me to go through your webpage. It definitely stretches the limits with the mind when you go through very good info and make an effort to interpret it properly. I am going to glance up this web site usually on my PC. Thanks for sharing

injury lawyer United States

8/4/2010 4:51:55 AM #

Passed through here, leave a mark!
http://www.coachoutletmalls.com/   Coach factory outlet
http://www.guccihandbagsoutlet.com/   Gucci outlet online
http://www.coachoutletmalls.com/    Coach online outlet store
This article is written by zocy003 on 2010-8-4

Coach factory outlet People's Republic of China

8/4/2010 4:54:10 AM #

Passed through here, leave a mark!
http://www.coachoutletmalls.com/   Coach factory outlet
http://www.guccihandbagsoutlet.com/   Gucci outlet online
http://www.coachoutletmalls.com/    Coach online outlet store
This article is written by zocy003 on 2010-8-4

Coach factory outlet People's Republic of China

8/4/2010 4:54:21 AM #

Passed through here, leave a mark!
http://www.coachoutletmalls.com/   Coach factory outlet
http://www.guccihandbagsoutlet.com/   Gucci outlet online
http://www.coachoutletmalls.com/    Coach online outlet store
This article is written by zocy003 on 2010-8-4

Coach factory outlet People's Republic of China

8/4/2010 4:56:12 AM #

Passed through here, leave a mark!
http://www.coachoutletmalls.com/   Coach factory outlet
http://www.guccihandbagsoutlet.com/   Gucci outlet online
http://www.coachoutletmalls.com/    Coach online outlet store
This article is written by zocy003 on 2010-8-4

Coach factory outlet People's Republic of China

8/9/2010 6:36:37 AM #

Thanks so much for this.  I've been looking all over for something like this.

trade forex online Singapore

8/24/2010 12:39:53 PM #

Thank you for posting this article. I will bookmark your site to read more of your updated post.

Wage Garnishment United States

8/28/2010 3:05:25 PM #

thanks for the info on Asp..

registry cleaner reviews Spain

8/31/2010 9:50:54 PM #

Great tutorial. You make it look so easy. Thanks to you, I won't have to aimlessly search for a solution any longer.

Usp Labs Jack3d United States

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Sobre Mim

Felipe Augusto Silva Lambert - Analista de Sistemas, experiência em 3 anos desenvolvimento ASP.NET, utilizando tecnologias ServerSide (Design Patterns, Linq, WCF, SQL Server, C# e VB.NET) e ClientSide (JavaScript e Jquery). técnico em Mecatrônica e bacharel em Ciência da Computação.