Click here to monitor SSC
  • Av rating:
  • Total votes: 600
  • Total comments: 152
Gaidar Magdanurov

A Complete URL Rewriting Solution for ASP.NET 2.0

01 March 2007
Untitled 1

This article describes a complete solution for URL rewriting in ASP.NET 2.0. The solution uses regular expressions to specify rewriting rules and resolves possible difficulties with postback from pages accessed via virtual URLs.

Why use URL rewriting?

The two main reasons to incorporate URL rewriting capabilities into your ASP.NET applications are usability and maintainability.

Usability

It is well-known that users of web applications prefer short, neat URLs to monstrous addresses packed with difficult to comprehend query string parameters. From time to time, being able to remember and type in a concise URL is less time-consuming than adding the page to a browser's favorites to access later. Again, when access to a browser's favorites is unavailable, it can be more convenient to type in the URL of a page on the browser address bar, without having to remember a few keywords and type them into a search engine in order to find the page.

Compare the following two addresses and decide which one you like more:

  1. http://www.somebloghost.com/Blogs/Posts.aspx?Year=2006&Month=12&Day=10
  2. http://www. somebloghost.com/Blogs/2006/12/10/

The first URL contains query string parameters to encode the date for which some blog engines should show available postings. The second URL contains this information in the address, giving the user a clear idea of what he or she is going to see. The second address also allows the user to hack the URL to see all postings available in December, simply by removing the text encoding the day '10': http://www.somehost.com/Blogs/2006/12/.

Maintainability

In large web applications, it is common for developers to move pages from one directory to another. Let us suppose that support information was initially available at http://www.somebloghost.com/Info/Copyright.aspx and http://www.somebloghost.com/Support/Contacts.aspx, but at a later date the developers moved the Copyright.aspx and Contacts.aspx pages to a new folder called Help. Users who have bookmarked the old URLs need to be redirected to the new location. This issue can be resolved by adding simple dummy pages containing calls to Response.Redirect(new location). However, what if there are hundreds of moved pages all over the application directory? The web project will soon contain too many useless pages that have the sole purpose of redirecting users to a new location.

Enter URL rewriting, which allows a developer to move pages between virtual directories just by editing a configuration file. In this way, the developer can separate the physical structure of the website from the logical structure available to users via URLs.

Native URL mapping in ASP.NET 2.0

ASP.NET 2.0 provides an out-of-the-box solution for mapping static URLs within a web application. It is possible to map old URLs to new ones in web.config without writing any lines of code. To use URL mapping, just create a new urlMappings section within the system.web section of your web.config file and add the required mappings (the path ~/ points to the root directory of the web application):

<urlMappings enabled="true">

   <add url="~/Info/Copyright.aspx" mappedUrl="~/Help/Copyright.aspx" />

   <add url="~/Support/Contacts.aspx" mappedUrl="~/Help/Contacts.aspx" />

</urlMappings>

Thus, if a user types http://www.somebloghost.com/Support/Contacts.aspx, he can then see the page located at http://www.somebloghost.com/Help/Contacts.aspx, without even knowing the page had been moved.

This solution is fine if you have only two pages that have been moved to other locations, but it is completely unsuitable where there are dozens of re-located pages, or where a really neat URL needs to be created.

Another possible disadvantage of the native URL mapping technique is that if the page Contacts.aspx contains elements initiating postback to the server (which is most probable), then the user will be surprised that the URL http://www.somebloghost.com/Support/Contacts.aspx changes to http://www.somebloghost.com/Help/Contacts.aspx. This happens because the ASP.NET engine fills the action attribute of the form HTML tag with the actual path to a page. So the form renders like this:

<form name="formTest" method="post"
action="../Help/Contacts.aspx" id="formTest">

</form>

Thus, URL mapping available in ASP.NET 2.0 is almost always useless. It would be much better to be able to specify a set of similar URLs in one mapping rule. The best solution is to use Regular Expressions (for overview see Wikipedia and for implementation in .NET see MSDN), but an ASP.NET 2.0 mapping does not support regular expressions. We therefore need to develop a different solution to built-in URL mapping.

The URL rewriting module 

The best way to implement a URL rewriting solution is to create reusable and easily configurable modules, so the obvious decision is to create an HTTP Module (for details on HTTP Modules see MSDN Magazine) and implement it as an individual assembly. To make this assembly as easy to use as possible, we need to implement the ability to configure the rewrite engine and specify rules in a web.config file.

During the development process we need to be able to turn the rewriting module on or off (for example if you have a bug that is difficult to catch, and which may have been caused by incorrect rewriting rules). There should, therefore, be an option in the rewriting module configuration section in web.config to turn the module on or off. So, a sample configuration section within web.config can go like this:

<rewriteModule>

  <rewriteOn>true</rewriteOn>

  <rewriteRules>

      <rule source="(\d+)/(\d+)/(\d+)/"
        
destination="Posts.aspx?Year=$1&amp;Month=$2&amp;Day=$3"/>

      <rule source="(.*)/Default.aspx"
        
destination="Default.aspx?Folder=$1"/>

  </rewriteRules>

</rewriteModule>

This means that all requests that run like: http://localhost/Web/2006/12/10/ should be internally redirected to the page Posts.aspx with query string parameters.

Please note that web.config is a well-formed XML file, and it is prohibited to use the symbol & in attribute value strings. In this case, you should use &amp; instead in the destination attribute of the rule element.

To use the rewriteModule section in the web.config file, you need to register a section name and a section handler for this section. To do this, add a configSections section to web.config:

 <configSections>

    <sectionGroup name="modulesSection">

      <section name="rewriteModule" type="RewriteModule.
RewriteModuleSectionHandler, RewriteModule
"/>

    </sectionGroup>

  </configSections>

This means you may use the following section below the configSections section:

<modulesSection>

    <rewriteModule>

      <rewriteOn>true</rewriteOn>

      <rewriteRules>

              <rule source="(\d+)/(\d+)/(\d+)/"
destination="Post.aspx?Year=$1&amp;Month=$2&amp;Day=$3"/>

              <rule source="(.*)/Default.aspx"
destination="Default.aspx?Folder=$1"/>

      </rewriteRules>

    </rewriteModule>

  </modulesSection>

Another thing we have to bear in mind during the development of the rewriting module is that it should be possible to use 'virtual' URLs with query string parameters, as shown in the following: http://www.somebloghost.com/2006/12/10/?Sort=Desc&SortBy=Date. Thus we have to develop a solution that can detect parameters passed via query string and also via virtual URL in our web application.

So, let’s start by building a new Class Library. We need to add a reference to the System.Web assembly, as we want this library to be used within an ASP.NET application and we also want to implement some web-specific functions at the same time. If we want our module to be able to read web.config, we need to add a reference to the System.Configuration assembly.

Handling the configuration section

To be able to read the configuration settings specified in web.config, we have to create a class that implements the IConfigurationSectionHandler interface (see MSDN for details). This can be seen below:

using System;

using System.Collections.Generic;

using System.Text;

using System.Configuration;

using System.Web;

using System.Xml;

 

 

namespace RewriteModule

{

    public class RewriteModuleSectionHandler : IConfigurationSectionHandler

    {

 

        private XmlNode _XmlSection;

        private string _RewriteBase;

        private bool _RewriteOn;

 

        public XmlNode XmlSection

        {

            get { return _XmlSection; }

        }

 

        public string RewriteBase

        {

            get { return _RewriteBase; }

        }

 

        public bool RewriteOn

        {

            get { return _RewriteOn; }

        }

        public object Create(object parent,
                            object configContext,
                            System.Xml.XmlNode section)

        {

            // set base path for rewriting module to

            // application root

            _RewriteBase = HttpContext.Current.Request.ApplicationPath + "/";

 

            // process configuration section

            // from web.config

            try

            {

                _XmlSection = section;

                _RewriteOn = Convert.ToBoolean(
                            section.SelectSingleNode("rewriteOn").InnerText);

            }

            catch (Exception ex)

            {

                throw (new Exception("Error while processing RewriteModule
configuration section."
, ex));

            }

            return this;

        }

    }

}

The Class RewriteModuleSectionHandler will be initialized by calling the Create method with the rewriteModule section of web.config passed as XmlNode. The SelectSingleNode method of the XmlNode class is used to return values for module settings.

Using parameters from rewritten URL

When handling virtual URLS such as http://www. somebloghost.com/Blogs/gaidar/?Sort=Asc (that is, a virtual URL with query string parameters), it is important that you clearly distinguish parameters that were passed via a query string from parameters that were passed as virtual directories. Using the rewriting rules specified below:

<rule source="(.*)/Default.aspx" destination="Default.aspx?Folder=$1"/>,

You can use the following URL:

http://www. somebloghost.com/gaidar/?Folder=Blogs

...and the result will be the same as if you used this URL:

http://www. somebloghost.com/Blogs/gaidar/

To resolve this issue, we have to create some kind of wrapper for 'virtual path parameters'. This could be a collection with a static method to access the current parameters set:

using System;

using System.Collections.Generic;

using System.Text;

using System.Collections.Specialized;

using System.Web;

 

namespace RewriteModule

{

 

    public class RewriteContext

    {

        // returns actual RewriteContext instance for

        // current request

        public static RewriteContext Current

        {

            get

            {

                // Look for RewriteContext instance in

                // current HttpContext. If there is no RewriteContextInfo

                // item then this means that rewrite module is turned off

                if(HttpContext.Current.Items.Contains("RewriteContextInfo"))

                    return (RewriteContext)
HttpContext.Current.Items["RewriteContextInfo"];

                else

                    return new RewriteContext();

            }

        }

 

        public RewriteContext()

        {

            _Params = new NameValueCollection();

            _InitialUrl = String.Empty;

        }

 

        public RewriteContext(NameValueCollection param, string url)

        {

            _InitialUrl = url;

            _Params = new NameValueCollection(param);

           

        }

 

        private NameValueCollection _Params;

 

        public NameValueCollection Params

        {

            get { return _Params; }

            set { _Params = value; }

        }

 

        private string _InitialUrl;

 

        public string InitialUrl

        {

            get { return _InitialUrl; }

            set { _InitialUrl = value; }

        }

    }

}

You can see from the above that it is possible to access 'virtual path parameters' via the RewriteContext.Current collection and be sure that those parameters were specified in the URL as virtual directories or pages names, and not as query string parameters.

Rewriting URLs

Now let's try some rewriting. First, we need to read rewriting rules from the web.config file. Secondly, we need to check the actual URL against the rules and, if necessary, do some rewriting so that the appropriate page is executed.

We create an HttpModule:

class RewriteModule : IHttpModule
{

public void Dispose() { }
public void Init(HttpApplication context)

{}

}

When adding the RewriteModule_BeginRequest method that will process the rules against the given URL, we need to check if the given URL has query string parameters and call HttpContext.Current.RewritePath to give control over to the appropriate ASP.NET page.

using System;

using System.Collections.Generic;

using System.Text;

using System.Web;

using System.Configuration;

using System.Xml;

using System.Text.RegularExpressions;

using System.Web.UI;

using System.IO;

using System.Collections.Specialized;

 

namespace RewriteModule

{

    class RewriteModule : IHttpModule

    {

 

        public void Dispose() { }

 

        public void Init(HttpApplication context)

        {

            // it is necessary to

            context.BeginRequest += new EventHandler(
                 RewriteModule_BeginRequest);

        }

 

        void RewriteModule_BeginRequest(object sender, EventArgs e)

        {

 

            RewriteModuleSectionHandler cfg =
(RewriteModuleSectionHandler)
ConfigurationManager.GetSection
("modulesSection/rewriteModule");

 

            // module is turned off in web.config

            if (!cfg.RewriteOn) return;

 

            string path = HttpContext.Current.Request.Path;

 

            // there us nothing to process

            if (path.Length == 0) return;

 

            // load rewriting rules from web.config

            // and loop through rules collection until first match

            XmlNode rules = cfg.XmlSection.SelectSingleNode("rewriteRules");

            foreach (XmlNode xml in rules.SelectNodes("rule"))

            {

                try

                {

                    Regex re = new Regex(
                     cfg.RewriteBase + xml.Attributes["source"].InnerText,
                     RegexOptions.IgnoreCase);

                    Match match = re.Match(path);

                    if (match.Success)

                    {

                        path = re.Replace(
                             path,
                             xml.Attributes["destination"].InnerText);

                        if (path.Length != 0)

                        {

                            // check for QueryString parameters

                       if(HttpContext.Current.Request.QueryString.Count != 0)

                       {

                       // if there are Query String papameters

                       // then append them to current path

                       string sign = (path.IndexOf('?') == -1) ? "?" : "&";

                       path = path + sign +
                          HttpContext.Current.Request.QueryString.ToString();

                       }

                       // new path to rewrite to

                       string rew = cfg.RewriteBase + path;

                       // save original path to HttpContext for further use

                       HttpContext.Current.Items.Add(

                         "OriginalUrl",

                         HttpContext.Current.Request.RawUrl);

                       // rewrite

                       HttpContext.Current.RewritePath(rew);

                       }

                       return;

                    }

                }

                catch (Exception ex)

                {

                    throw (new Exception("Incorrect rule.", ex));

                }

            }

            return;

        }

 

    }

}

 

We must then register this method:

public void Init(HttpApplication context)

{

 context.BeginRequest += new EventHandler(RewriteModule_BeginRequest);

}

But this is just half of the road we need to go down, because the rewriting module should handle a web form's postbacks and populate a collection of 'virtual path parameters'. In the given code you will not find a part that does this task. Let's put 'virtual path parameters' aside for a moment. The main thing here is to handle postbacks correctly.

If we run the code above and look through the HTML source of the ASP.NET page for an action attribute of the form tag, we find that even a virtual URL action attribute contains a path to an actual ASP.NET page. For example, if we are using the page ~/Posts.aspx to handle requests like:

http://www. somebloghost.com/Blogs/2006/12/10/Default.aspx
,

...we find the action="/Posts.aspx". This means that the user will be using not the virtual URL on postback, but the actual one: http://www. somebloghost.com/Blog.aspx. This is not what we want to use here! So, a few more lines of code are required to achieve the desired result.

First, we must register and implement one more method in our HttpModule:

        public void Init(HttpApplication context)

        {

            // it is necessary to

            context.BeginRequest += new EventHandler(
                 RewriteModule_BeginRequest);

            context.PreRequestHandlerExecute += new EventHandler(
                 RewriteModule_PreRequestHandlerExecute);

        }

 

      void RewriteModule_PreRequestHandlerExecute(object sender, EventArgs e)

        {

            HttpApplication app = (HttpApplication)sender;

            if ((app.Context.CurrentHandler is Page) &&
                 app.Context.CurrentHandler != null)

            {

                Page pg = (Page)app.Context.CurrentHandler;

                pg.PreInit += new EventHandler(Page_PreInit);

            }

        }

This method checks if the user requested a normal ASP.NET page and adds a handler for the PreInit event of the page lifecycle. This is where RewriteContext will be populated with actual parameters and a second URL rewriting will be performed. The second rewriting is necessary to make ASP.NET believe it wants to use a virtual path in the action attribute of an HTML form.

void Page_PreInit(object sender, EventArgs e)

        {

            // restore internal path to original

            // this is required to handle postbacks

            if (HttpContext.Current.Items.Contains("OriginalUrl"))

            {

              string path = (string)HttpContext.Current.Items["OriginalUrl"];

 

              // save query string parameters to context

              RewriteContext con = new RewriteContext(
                HttpContext.Current.Request.QueryString, path);

 

              HttpContext.Current.Items["RewriteContextInfo"] =  con;

 

              if (path.IndexOf("?") == -1)

                  path += "?";

              HttpContext.Current.RewritePath(path);

            }

        }

Finally, we see three classes in our RewriteModule assembly:

Registering RewriteModule in web.config

To use RewriteModule in a web application, you should add a reference to the rewrite module assembly and register HttpModule in the web application web.config file. To register HttpModule, open the web.config file and add the following code into the system.web section:

<httpModules>

<add name="RewriteModule" type="RewriteModule.RewriteModule, RewriteModule"/>

</httpModules>

Using RewriteModule

There are a few things you should bear in mind when using RewriteModule:

  • It is impossible to use special characters in a well-formed XML document which is web.config in its nature. You should therefore use HTML-encoded symbols instead. For example, use &amp; instead of &.
  • To use relative paths in your ASPX pages, you should call the ResolveUrl method inside HTML tags: <img src="<%=ResolveUrl("~/Images/Test.jpg")%>" />. Note, that ~/ points to the root directory of a web application.
  • Bear in mind the greediness of regular expressions and put rewriting rules to web.config in order of their greediness, for instance
<rule source="Directory/(.*)/(.*)/(.*)/(.*).aspx"
destination="Directory/Item.aspx?
Source=$1&amp;Year=$2&amp;ValidTill=$3&amp;Sales=$4"/>
<rule source="Directory/(.*)/(.*)/(.*).aspx"
destination="Directory/Items.aspx?
Source=$1&amp;Year=$2&amp;ValidTill=$3"/>
<rule source="Directory/(.*)/(.*).aspx"
destination="Directory/SourceYear.aspx?
Source=$1&amp;Year=$2&amp;"/>
<rule source="Directory/(.*).aspx"
destination="Directory/Source.aspx?Source=$1"/>
  • If you would like to use RewriteModule with pages other than .aspx, you should configure IIS to map requests to pages with the desired extensions to ASP.NET runtime as described in the next section.

IIS Configuration: using RewriteModule with extensions other than .aspx

To use a rewriting module with extensions other than .aspx (for example, .html or .xml), you must configure IIS so that these file extensions are mapped to the ASP.NET engine (ASP.NET ISAPI extension). Note that to do so, you have to be logged in as an Administrator.

Open the IIS Administration console and select a virtual directory website for which you want to configure mappings.

Windows XP (IIS 5)
Virtual Directory "RW"                                

 

Windows 2003 Server (IIS 6)
Default Web Site

Then click the Configuration… button on the Virtual Directory tab (or the Home Directory tab if you are configuring mappings for the website).

Windows XP (IIS 5)                     

Windows 2003 Server (IIS 6)

Next, click on the Add button and type in an extension. You also need to specify a path to an ASP.NET ISAPI Extension. Don't forget to uncheck the option Check that file exists.

If you would like to map all extensions to ASP.NET, then for IIS 5 on Windows XP you have only to map .* extension to the ASP.NET ISAPI extension. But for IIS 6 on Windows 2003 you have to do it in a slightly different way: click on the Insert… button instead of the Add… button, and specify a path to the ASP.NET ISAPI extension.

Conclusions

Now we have built a simple but very powerful rewriting module for ASP.NET that supports regular expressions-based URLs and page postbacks. This solution is easily implemented and gives users the ability to use short, neat URLs free of bulky Query String parameters. To start using the module, you simply have to add a reference to the RewriteModule assembly in your web application and add a few lines of code to the web.config file, whereupon you have all the power of regular expressions at your disposal to override URLs. The rewrite module is easily maintainable, because to change any 'virtual' URL you only need to edit the web.config file. If you need to test your application without the module, you can turn it off in web.config without modifying any code.

To gain a deeper insight into the rewriting module, take a look through the source code and example attached to this article. I believe you'll find using the rewriting module a far more pleasant experience, than using the native URL mapping in ASP.NET 2.0.

Gaidar Magdanurov

Author profile:

Gaidar, an MVP for Visual Basic, lives in Moscow. His primary job is scientific research in INEOS RAS. Gaidar also works as a software developer/consultant and is editor-in-chief of the VBStreets web site, dedicated to Visual Basic and Microsoft .NET technologies. An active member of the Russian GotDotNet community, Gaidar also enjoys speaking at user-group meetings. In his spare time, Gaidar likes playing the guitar, going to the theater, walking in the park and visiting friends.

Search for other articles by Gaidar Magdanurov

Rate this article:   Avg rating: from a total of 600 votes.


Poor

OK

Good

Great

Must read
Have Your Say
Do you have an opinion on this article? Then add your comment below:
You must be logged in to post to this forum

Click here to log in.


Subject: The definitive resource for ASP.Net 2.0 URL rewrites
Posted by: Anonymous (not signed in)
Posted on: Monday, March 05, 2007 at 11:27 AM
Message: There are many articles that pretend to address this topic, but this is the first complete explanation that I have seen. Thank you.

Subject: Extension-less URL Rewriting
Posted by: Anonymous (not signed in)
Posted on: Wednesday, March 07, 2007 at 1:16 AM
Message: While your article is good, you neglect to mention how to accomplish Extension-less URL Rewriting
despite the fact you mention URLs without extensions quite a bit:
e.g. http://www. somebloghost.com/Blogs/2006/12/10/

Scott Guthrie covers this (and a lot of the same ground you cover) in his article over at

http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

Subject: Complete one
Posted by: Anonymous (not signed in)
Posted on: Wednesday, March 07, 2007 at 3:11 AM
Message: I have gone through many article on same topic, this is one where i found all most all the subtopic what i needed
thanks

Subject: Good article
Posted by: Anonymous (not signed in)
Posted on: Thursday, March 08, 2007 at 11:31 AM
Message: But there is one problem:

How is somebody going to edit IIS properties on shared hosting server?

IIS sucks, period.

Subject: Good Article
Posted by: Anonymous (not signed in)
Posted on: Friday, March 09, 2007 at 9:22 PM
Message: Yes , it Helped me a Lot

Thank you Very Much

Subject: Good Article
Posted by: Anonymous (not signed in)
Posted on: Saturday, March 10, 2007 at 4:11 AM
Message: Yes, its really a good article.

Thanks for this

Subject: Good article
Posted by: Anonymous (not signed in)
Posted on: Monday, March 12, 2007 at 6:14 AM
Message: thanks

Subject: Rule Question
Posted by: Anonymous (not signed in)
Posted on: Thursday, March 22, 2007 at 3:54 PM
Message: Hello. What would be the proper way to set up a rule in Web.config to point:

/Test/1.aspx

to

/Test.aspx?id=1

I tried the following, but it didn't seem to work:

<rule
source="~/Test/(.*).aspx"
destination="~/Test.aspx?Source=$1" />

Also tried:

<rule
source="~/Test/(\d{1,5}).aspx"
destination="~/Test.aspx?Source=$1" />

Any advice?

Thanks!

Subject: urgent (need Help)
Posted by: Anonymous (not signed in)
Posted on: Friday, March 23, 2007 at 7:13 AM
Message: I have done this part in web.config file and it is working when i start from local machine.
like ==> http://localhost:4683/Rentslicer/California


But when i was try to start from my ip address it is not working .
like ==>http://125.6.3.139/California

So what should i do??


<urlMappings enabled="true">
<add url="~/California" mappedUrl="~/state.aspx?State=CA&alt=California"/>
<add url="~/Washington" mappedUrl="~/state.aspx?State=WA&alt=Washington"/>

Subject: IIS6 404?
Posted by: Anonymous (not signed in)
Posted on: Monday, March 26, 2007 at 1:26 PM
Message: Great article!

I have followed your setup etc. and no matter what I try, IIS6 (Win2k3 server) returns a 404 when I try to access the URL that needs to be re-written. For example:

http://www.foo.com/Books/123 should be re-written as http://www.foo.com/Books.aspx?ID=123

but IIS always seems to return the generic 404 error page (“page or directory not found” – there is no “Books” directory on the web root). Any thoughts to what IIS setting might be causing this?

Thanks!

Subject: Re : IIS6 404 ( By Bhaskar Bahal)
Posted by: Anonymous (not signed in)
Posted on: Monday, March 26, 2007 at 11:53 PM
Message: Hi i have temporary Solution for this if you put
ttp://www.foo.com/Books/123.aspx Then it will work.

Subject: Re: IIS6 404?
Posted by: Anonymous (not signed in)
Posted on: Tuesday, March 27, 2007 at 8:34 AM
Message: I tried that (adding file extention to end)....as noted in some of the earlier comments.

Any other thoughts (IIS configuration settings, etc.)?

Subject: Answers
Posted by: Anonymous (not signed in)
Posted on: Thursday, March 29, 2007 at 7:17 AM
Message: Hello everybody!

Thank you for your interest. I will try to answer all of your questions:

1. If you want to rewrite /Test/1.aspx to /Test.aspx?id=1 you should use the following rule:

<rule source="Test/(.*)Default.aspx" destination="/Test.aspx?id=$1"/>,

2. Question with IP address is not for my rewriting solution but for integrated URL mapping functionality in ASP.NET. But I can answer - you have to configure IIS web server to handle .* (all extensions) with ASP.NET ISAPI filter to use extensionless URLs

3. As for 404 error - double check if you turn off Verify That File Exist option in IIS configuration for .* "extension"

Best,
Gaidar

Subject: Intresting
Posted by: Anonymous (not signed in)
Posted on: Friday, March 30, 2007 at 2:07 AM
Message: This article is really Helpfull

Subject: url rewriting
Posted by: Anonymous (not signed in)
Posted on: Monday, April 02, 2007 at 6:28 AM
Message: Hi every one explaining the Url Rewriting its really very usefully.can u explain very clearly and deeply

Subject: Thanks Gaider
Posted by: Anonymous (not signed in)
Posted on: Tuesday, April 03, 2007 at 7:03 AM
Message: Hi I am using Your Code in my application.
I have two problem.

1. On Production server the images of mapped url page is not showing.

2. Css is not apply to Pages.

Please correct me.

Subject: Gaider
Posted by: Anonymous (not signed in)
Posted on: Wednesday, April 04, 2007 at 5:44 AM
Message: Thanks Gaider Youhelp me lot

Now I am using Above code.But there is two problem.
1. I have to use every where Resolve url in my project.

<a class="BlueLink" href= "<%=ResolveUrl("ViewAllMarket.aspx?state=" + state )%>">View all markets ››</a>
instead of
<a class="BlueLink" href="ViewAllMarket.aspx?state=<%=state%>">View all markets ››</a>

Is there any thing So that i can use directly Href tag instead of Resolve url.
Because in project i have to change all URl and Image path
PLEASE suggest me its urgent

Subject: Problem
Posted by: Anonymous (not signed in)
Posted on: Wednesday, April 04, 2007 at 9:07 AM
Message: I use code in my web site, but after set in IIS configuration for .* "extension" checkbox - "check that file exist" on off.

1. CSS style is not apply to pages

2. When try to open file from virtual folder

System.Drawing.Image.FromFile(Server.MapPath("~/" + ConfigurationManager.AppSettings["Images"]) + imageURL);

i catch exception ot type "FileNotFoundException" , but file exist and path is correct.

if i set checkbox on "on" then these problem not exist, but urlrewrite on type:

from "mysite/product/1234"
to "mysite/product.aspx?id=1234" don't work.

Subject: Great
Posted by: Anonymous (not signed in)
Posted on: Friday, April 13, 2007 at 1:26 AM
Message: Hi.. I found many articles on this..its nice to see much more explanation on this article..

Great work...


Subject: hide aspx to htm
Posted by: Anonymous (not signed in)
Posted on: Thursday, April 19, 2007 at 8:24 AM
Message: plz sugget some way to hide aspx as htm

Subject: Not invented here?
Posted by: Anonymous (not signed in)
Posted on: Thursday, April 26, 2007 at 9:37 AM
Message: You could just try using an open source url rewriter like http://urlrewriter.net/

Subject: Help
Posted by: Anonymous (not signed in)
Posted on: Friday, April 27, 2007 at 7:49 AM
Message: Gaidar Magdanurov,

Thanks for your post. We have used your code in our project but we are facing a problem that its working fine in 5.1 but not working in 6.0. Please give the solution for this.

You can check this problem online at:
http://www.bramptonpages.com/8/Electronics-And-Semiconductors/Default.aspx

But the same is working on:
http://localhost/BramptonPages/8/Electronics-And-Semiconductors/Default.aspx

Thanks in advance


Subject: Why not just use Global.asax?
Posted by: Anonymous (not signed in)
Posted on: Friday, April 27, 2007 at 8:11 PM
Message: For those of you that are on shared hosting try using the following code in this article:

http://www.willasrari.com/blog/rewrite-url-without-using-filenames-or-extensions-c/000109.aspx

Subject: rewrite not working on live server
Posted by: Anonymous (not signed in)
Posted on: Friday, May 04, 2007 at 7:11 PM
Message: I was able to get your code to work on my local development machine but when I put it on the live server and checked what was being compared, RewriteBase had an extra slash at the beginning i.e. //blogs/default.aspx but the path only had 1 slash. I found this out by raising an error if there was no match and displaying the 2.
If I try to do a replace the page that keeps trying to load.
I am not using and Regular expression comaparisons just blogs/derectory/default.aspx for the source and blogs/default.aspx for the destination.

Thanks
Royal

Subject: rewrite not working on live server
Posted by: Anonymous (not signed in)
Posted on: Friday, May 04, 2007 at 9:18 PM
Message: I was able to get your code to work on my local development machine but when I put it on the live server and checked what was being compared, RewriteBase had an extra slash at the beginning i.e. //blogs/default.aspx but the path only had 1 slash. I found this out by raising an error if there was no match and displaying the 2.
If I try to do a replace the page that keeps trying to load.
I am not using and Regular expression comaparisons just blogs/derectory/default.aspx for the source and blogs/default.aspx for the destination.

Thanks
Royal

Subject: There is a bug !! Please see here.
Posted by: doggy8088 (view profile)
Posted on: Sunday, May 06, 2007 at 2:24 PM
Message: Your module will not execute smoothly when install website in root web application:

Line 36 of RewriteModuleSectionHandler.cs:

_RewriteBase = HttpContext.Current.Request.ApplicationPath + "/";

Should rewrite as

if (!HttpContext.Current.Request.ApplicationPath.EndsWith("/"))
{
_RewriteBase = HttpContext.Current.Request.ApplicationPath + "/";
}


That's because when your web ap run in root url, the HttpContext.Current.Request.ApplicationPath will be "/", if you append an "/" will cause file not found error.

Subject: Avoid .* and make sure you're not missing files
Posted by: Anonymous (not signed in)
Posted on: Thursday, May 10, 2007 at 1:16 AM
Message: Mapping .* to aspnet_isapi means that every file on the web server is served up by ASP.NET. You're giving .NET processing duties that are normally handled by IIS. When a page loads, .NET isn't handling one page, it's handling one page PLUS any number of .css, .js, .gif, .jpg, or .png files. Multiply that by every page load of every user of every site on the server, and .NET's performance starts to degrade.

Instead, you can set the custom 404 error in IIS to point to something like URL /404.aspx and handle the rewriting from there. That way, .NET only needs to handle missing files, like "/MyVirtualPage/".

In either case, it's important to make sure you aren't missing any images or linked files. If any file is missing, ASP.NET will return its 404 error page (or your custom 404 page), doing extra work for no reason.

Now let's take it a step further to witness the destructive potential of a single missing image. Let's say you have a master page (or a control used on all pages), and it has an image tag pointing to an image that no longer exists. When it can't find the image, the Web.config tells .NET to load your custom 404 page. But your custom 404 page uses the same master page with the same missing image, so now you've got an infinite loop, dragging down the performance of the entire server.

Subject: Scott Mitchell...
Posted by: Anonymous (not signed in)
Posted on: Friday, May 11, 2007 at 10:41 AM
Message: It appears as if you based this off Scott Mitchell's URL Rewriting guide. You should definitely cite your sources....

Subject: Virtual url files
Posted by: Anonymous (not signed in)
Posted on: Friday, May 11, 2007 at 5:55 PM
Message: My assumption is that the virtual url doesn't have to really exist but if I use the below rule I get the error
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Rewrite.Test/blogs/Caroline/blogs.aspx


Rule:
<rule source="(\d+)/(\d+)/(\d+)/" destination="Default2.aspx?blogID=333"/>

I didn't think that the caroline/blogs.aspx had to really exist.

Thanks
Royal

Subject: Maintainability and Usability
Posted by: Anonymous (not signed in)
Posted on: Wednesday, May 16, 2007 at 10:56 AM
Message: A good article, although usability and maintainability are not good reasons to consider rewrting your urls. A user experienced enough to manipulate the flattened will be able to manipulate the dynamic version. I also do not want users manipulating url's if i can help it.

However rewriting your urls as meaningful textual phrases is a great idea, not just for the user but more importantly for search engines!!!

Subject: Answers
Posted by: Anonymous (not signed in)
Posted on: Friday, May 18, 2007 at 7:47 AM
Message:
Sorry that it took too long for me to get here and answer your questions - I do apologize but I'm really busy these days.

First of all, most of the problems arise because of relative paths, so it is better to use paths starting from the root. Thus, you should use the following for an image:
<img src="<%=ResolveUrl("~/Images/MyImage.jpg")%>" />
or the following for CSS:
<link rel="stylesheet" href="<%=ResolveUrl("~/Css/MyCss.css")%>" type="text/css" />

Of course, you may use direct href tag if you are specifying url starting from the root, e.g.:
<a href="/MySite/Page/MyPage.aspx" />

This is a price you have to pay for URL rewriting...

The next "problem generator" is regular expression you are using...

For BramptonPages - could you please show me rewriting rules you are using?

Doubled slash (//) not raising issues actually because it is simple ignored... But your solution is good, I had to do that. Thanks!

As for mapping .* to ASP.NET - I myself don't like the idea (maybe because I'm served by ASP.NET I like to know it is ASP.NET from the URL and not .php or .pl :)).

As for Scott Mitchell's article. I have not seen it before because I have been using this type of rewriting for more than 3 years now and never Google/Live/Yahoo and etc. for rewriting solutions...

As for this rule:

<rule source="(\d+)/(\d+)/(\d+)/" destination="Default2.aspx?blogID=333"/>

Your regular expression simply is wrong - it will do for something like /Rewrite.Test/10/20/30/. If you like to use a rule for /Rewrite.Test/blogs/Caroline/blogs.aspx then you have to use the following rule:

<rule source="(\w+)/(\w+)/(\w+).aspx/" destination="Default2.aspx?blogID=333"/>

Thank you all for your comments!

Subject: Urgent
Posted by: subrat (view profile)
Posted on: Monday, May 21, 2007 at 2:04 AM
Message: Hi I am using Your Code in my application.
I have two problem.

1. On Production server the images of mapped url page is not showing.

2. Css is not apply to Pages.

Please correct me.

Subject: urgent reply me plz
Posted by: Anonymous (not signed in)
Posted on: Wednesday, May 23, 2007 at 4:59 AM
Message: When i go for live server it is giving 404 error
plz tell be very urgent
<rewriteRules>
<rule source="(.+)/(.+)/(.+)/" destination="Neighbourhood.aspx?StateName=$1&CityArea=$2&neigh=$3"/>
</rewriteRules>



Please tell me is there i have to config iis
My url like
www.mycompany.com/california/losangles/mailbu/
is not working

Subject: Alternative
Posted by: Florin L. (not signed in)
Posted on: Tuesday, May 29, 2007 at 6:15 AM
Message: I just tried "urlrewriting.net" and it does the trick, theme and image urls been handled properly.

Binary, Docs and Sources at:
http://www.urlrewriting.net/


Subject: Query
Posted by: subrat (view profile)
Posted on: Tuesday, June 05, 2007 at 3:58 AM
Message: When i mapped the URL my java script function is not working . How can it works . please mail me.

Subject: Nice effort
Posted by: Nauman Ahmed (not signed in)
Posted on: Tuesday, June 05, 2007 at 4:27 AM
Message: Very nice article

Subject: Query
Posted by: subrat (view profile)
Posted on: Tuesday, June 05, 2007 at 7:05 AM
Message: When i mapped the URL my java script function is not working . How can it works . please mail me.

Subject: Seems like it just doesn't trigger on the live site
Posted by: Anonymous (not signed in)
Posted on: Friday, June 22, 2007 at 10:14 AM
Message: This works fine when developing on my local machine:

<rule source="(\w+)/test.aspx" destination="$1.aspx"/>

but once pre-compiled and loaded on our development server, I get the error:

Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /search/test.aspx

Any clue what I'm missing?

Subject: Can I get the sample code in vbscript
Posted by: Vipul Parekh (not signed in)
Posted on: Tuesday, June 26, 2007 at 2:51 AM
Message: Hi,

This is the most detailed article I found on net. It will be gr8 if you can provide it in vbscript.

Regards,
Vipul Parekh

Subject: run RewriteModule in Medium Trust
Posted by: Choong (not signed in)
Posted on: Friday, June 29, 2007 at 7:52 PM
Message: Thank you for the fantastic sharing. This is really a good site to know how to rewrite the URl.

However, when it is compile to DLL, it will not run in shared hosting running under Medium Trust.

How and what should we do to counter this problem? Thank you.


Subject: Not working online
Posted by: Meghana (not signed in)
Posted on: Monday, July 09, 2007 at 7:24 AM
Message: This example is not working online. Please help for the same

Subject: Not working in share hosting.
Posted by: candyman (not signed in)
Posted on: Monday, July 09, 2007 at 12:13 PM
Message: I tested it in local, and it runs well.But I upload DLL in a share hosting, it can not run, please tell me why?. http://vnexhibition.net/ =>this's my site.

Subject: Urgent:: NOT GETTING ACCESS
Posted by: Anonymous (not signed in)
Posted on: Monday, July 23, 2007 at 9:05 AM
Message: Your code is in detail and specific but the problem i faced is :
my default URL is "http://localhost:1555/XYZ/mn.aspx"
and when i use the "http://192.168.1.2/XYZ/mn.aspx" ,which is the IP of the same machine, i could not access the pages, wherever the prior URL works properly.
For this reason i am not getting access these pages from other machines on the LAN and not from the internet (my server is configured as WEB server).
Plz solve my problem, i am not getting any solution. I had seen this type of problem in this topic but did not get any solution from you. So, plz solve my problem as early as possible.

thanks.

Subject: to fetch url of the address bar in a string
Posted by: Anonymous (not signed in)
Posted on: Saturday, August 04, 2007 at 2:59 AM
Message: hello sir,

how to fetch url(link) of the address bar (web page) in a string????????????[asp.net2.0 with c#)

Subject: re:to fetch url of the address bar in a string
Posted by: Anonymous (not signed in)
Posted on: Friday, September 07, 2007 at 6:32 AM
Message: try
HttpContext.Current.Request.RawUrl

Subject: Re:Urgent:: NOT GETTING ACCESS
Posted by: Bhaskar Bahal (not signed in)
Posted on: Tuesday, September 18, 2007 at 3:19 AM
Message: Hey This is for all
Please configure IIS other wise this will not work.
To handle .* (all extensions) with ASP.NET ISAPI filter to use extensionless URLs like *.aspx

Then it will work
http://192.168.1.2/XYZ/mn.aspx

Subject: Gud Solution
Posted by: Viraj (not signed in)
Posted on: Saturday, September 22, 2007 at 1:59 AM
Message: i m new to url rewriting.
here i found very easy solution to start with.
i appriciate the efforts.....

Subject: Url Rewriting/Mapping
Posted by: Anonymous (not signed in)
Posted on: Wednesday, September 26, 2007 at 2:33 PM
Message: Hello, Can u give me this code in vb.net insted of using c# language. ?

Subject: Not working online
Posted by: Sem GÖKSU = askisem@hotmail.com (not signed in)
Posted on: Friday, September 28, 2007 at 6:10 AM
Message: This example is not working on Windows Server 2003(iis 6.0). Please help for the same...

Sem GÖKSU = askisem@hotmail.com

Subject: Urgent !!! HttpContext.Current.Request.Path is working strangely
Posted by: Viru (not signed in)
Posted on: Tuesday, October 02, 2007 at 2:35 AM
Message: Hi,

I have tried your code in 2 applications.
One is working fine. The other is not and so I have describing that here.

Suppose,
There is one page
/project/productslisting.aspx?cat=3
I rewrite it as /project/cat/3/productslisting.aspx
It is working correctly. Now, the HttpContext.Current.Request.Path is /project/cat/3/productslisting.aspx

On this page paging has been applied, so as soon as I click on next page(i.e. LinkButton)
HttpContext.Current.Request.Path is changed to /project/productslisting.aspx

How strange! Please help me out because it works in other application perfectly. Thanks!


Subject: Urgent !!! HttpContext.Current.Request.Path is working
Posted by: Viru (not signed in)
Posted on: Tuesday, October 02, 2007 at 3:07 AM
Message: Hi,
I have found the bug. I have used <base href="http://project/"> tag to overcome the problem of css,images rendering so URL rewriting is not working and Request.path is changed. If I remove <base> css and images will not render and path will be proper. Now what should I do?

Subject: Yearby
Posted by: Yearby (not signed in)
Posted on: Tuesday, October 09, 2007 at 4:43 AM
Message: http://lopsite.com/cialis/buy-cialis-toronto.php

Subject: how to write a rule.
Posted by: Anonymous (not signed in)
Posted on: Tuesday, October 09, 2007 at 7:47 AM
Message: hi,
i have face one problem in that i have to need genrealized create a rule for the ex.

http://localhost/News.aspx
with
http://localhost/News
with same as any page's coming like
http://localhost/(pageName) and destination is that
(pagename).aspx




Subject: how to write a rule.
Posted by: Anonymous (not signed in)
Posted on: Tuesday, October 09, 2007 at 8:36 AM
Message: hi,
i have face one problem in that i have to need genrealized create a rule for the ex.

http://localhost/News.aspx
with
http://localhost/News
with same as any page's coming like
http://localhost/(pageName) and destination is that
(pagename).aspx




Subject: whatever
Posted by: Anonymous (not signed in)
Posted on: Tuesday, October 09, 2007 at 11:42 AM
Message: What a waste of time... Who cares if your URL looks nice or not.

Subject: url rewrite error
Posted by: hardik joshi (not signed in)
Posted on: Tuesday, October 16, 2007 at 3:32 AM
Message: When i use the above module in my application it gives me the error :--"The system cannot find the path specified."

I really need help in this. have i made any mistake in configuration.
please reply me tech2hard@gmail.com

Subject: Brilliant
Posted by: Simon (not signed in)
Posted on: Thursday, October 18, 2007 at 3:23 PM
Message: This is a fantastic solution. You don't know how hard I've tried to get other URL rewriting solutions working, and this one works perfectly for me. Thakns a lot!

Subject: Works in filesystem based website but not in IIS website
Posted by: Ambuj (not signed in)
Posted on: Saturday, October 20, 2007 at 8:51 AM
Message: Hello, excellent article!
I've been trying it out but due to some reason if I create a file system based website in VS2005, the redirection works. But when I create the website in IIS and run it from VS2005, it doesn't break into RewriteModule_BeginRequest and hence doesn't redirect - Any ideas? Thanks in advance

Subject: Redirecting from aspx to other.
Posted by: Anonymous (not signed in)
Posted on: Saturday, October 20, 2007 at 2:33 PM
Message: Hello. Thanks for your article its very good. I have functionating the rewriting. Thats meen when somebody do www.site.com/help its going to the good place www.site.com/newsite/helpContext/help.aspx (something like this)
But after that if a user go to a menu link it go to: producto.aspx?idP=1789& ... and I wold like that at that moment the URL that see the user was transformed to www.site.com/products

It is possible? Thank you very much
Natalia

Subject: URL Rewriting Help
Posted by: Hi need Help. Can any one help.. (not signed in)
Posted on: Tuesday, October 23, 2007 at 10:52 AM
Message: Hi all.. Im struggling to implement URL Rewriting. Can anyone please help me.

I have list of category and sub-category.

Eg., Category - Cars
Subcategory - Ford,Hyundai,etc..

When i select Cars, Im getting, Category.aspx?Catid=1
I dont want this kind of query string.
I want like user friendly query string like Category/cars/1/ or like tat.

How to implement this. I mean How to call the begin request to inline code or codebehind where we bind data to control..like

==================================
default.aspx.cs (code behind)

GridView1.Datasource = ds;
GridView1.Databind
==================================
default.aspx (Inline code or source)
==================================

<asp:GridView ID="GridView1" runat="server">
<Columns><asp:TemplateField>
<ItemTemplate>
<a href=“category.aspx?catid=“<%#Eval(“CatID“)%>
“><%#Eval(“CatName“)%></a>
</ItemTemplate>
</asp:TemplateField></Columns>
</asp:GridView>

How to implement the URL rewrite here. Please help me to get rid out of this. Thanks in advance...

Subject: Plss help
Posted by: rueny01 (view profile)
Posted on: Thursday, October 25, 2007 at 11:40 PM
Message: Could not load file or assembly 'RewriteModule' or one of its dependencies. The system cannot find the file specified. (<drive name>:\Documents and Settings\<user name>\<folder name>\UrlReWriting\web.config line 34)

Thanks in advance

Subject: Error in Web.config
Posted by: parani (not signed in)
Posted on: Friday, November 02, 2007 at 4:06 AM
Message: Could not load file or assembly 'RewriteModule' or one of its dependencies. The system cannot find the file specified.

Subject: Error when publishing RewriteModule
Posted by: Henryzhchen (not signed in)
Posted on: Tuesday, November 06, 2007 at 6:32 PM
Message: I open the "RewriteModule" with VS 2005 on Windows Vista. It's fine without publishing it. When I publishing it to another site, I got
"HTTP Error 500.0 - Internal Server Error"

I run the "%systemroot%\system32\inetsrv\APPCMD.EXE migrate config "Default Web Site/TestRewriteModule" from command line as recommended, I got following another error:

Parser Error Message: An error occurred creating the configuration section handler for modulesSection/rewriteModule: Error while processing RewriteModule configuration section.

Source Error:

Line 15: </configSections>
Line 16: <modulesSection>
Line 17: <rewriteModule>
Line 18: <rewriteOn></rewriteOn>
Line 19: <rewriteRules>

Can anyone help on this.

Thanks in advance.

Subject: Anonymous Comments Disabled
Posted by: Sarah Grady (view profile)
Posted on: Tuesday, November 27, 2007 at 6:17 AM
Message: Due to a high volume of spam, anonymous comments have been disabled.

Subject: Rule Question
Posted by: prashantvictory (view profile)
Posted on: Monday, December 03, 2007 at 2:53 AM
Message: I want to that if user type the following url like
mywebsite/blog
then the destination url should be
mywebsite.com/blog?which=blogstrip
How can i do this?????

Subject: PROBLEM Urgent
Posted by: krimashah (view profile)
Posted on: Monday, December 17, 2007 at 7:35 AM
Message: i have used the same DLL file , and i hava add that referrences in BIN. Now , in Web.config if i m write <modulesSection> then it gives me error , like Unorganized modulesSection in web.config.Pls help me.

Subject: PLS help me
Posted by: krimashah (view profile)
Posted on: Tuesday, December 18, 2007 at 6:27 AM
Message: it is not workin on thw live , like i want http://www.roadtriphelper.com/locate/pune/ then it will display a map of pune , but is it not working on live server. Pls help me.

Subject: Site working slow
Posted by: neerajmude1979 (view profile)
Posted on: Wednesday, December 26, 2007 at 6:25 AM
Message: Dear Sir,
First of thanks for this ultimate program. Here i m using this tool for my website and the site is online, But it is working too much slow. Rather than other sites are working too fast and i found the cause is web.config Here i writes all rule for rewriting in web.config and it become too slow.


So please give me suggestion to improve the speed for site and also the main problem of image path. i m included basic path with http:// . Just i m in confusion so please help me ASAP.


Thanks
Neeraj Mude
S/W Eng.

neerajmude1979@gmail.com

Subject: Please Reply Soon
Posted by: neerajmude1979 (view profile)
Posted on: Friday, December 28, 2007 at 7:00 AM
Message: Respected Sir ,

Please reply soon. I m waiting .......

neerajmude1979@gmail.com

Subject: Error Hosting
Posted by: Kimsea (view profile)
Posted on: Saturday, January 19, 2008 at 2:05 AM
Message: Dear Gaidar Magdanurov,

Your code work well, when I run with Microsoft Visual Studio Professional 2005 on my local machine. Then I run this code on my Hosting, it didn't work. And I ask my hosting he reply that your dll url rewrite did not work.

Please help me,
Thank You,

Subject: Please Help Me
Posted by: Kimsea (view profile)
Posted on: Sunday, January 20, 2008 at 10:32 PM
Message: Dear Gaidar Magdanurov,

Please help me for your code. Because I use this code make URL Rewriting, But it work only run with Visual Studio Professtional 2005. And I publish this code and put on my hosting doesn't work.

How should I do?

Thank you,

Subject: SiteMapDataSource
Posted by: neilx (view profile)
Posted on: Friday, March 07, 2008 at 9:59 AM
Message: This works for me apart from using a SiteMap with a SiteMapDataSource and a Menu Control. No virtual folder is appended.

Any ideas on how to do this?

Subject: It works!
Posted by: http://www.aspdotnetfaq.com (view profile)
Posted on: Friday, March 28, 2008 at 4:36 PM
Message: Works perfect!

Thanks,
Slobo

Subject: It works!
Posted by: http://www.aspdotnetfaq.com (view profile)
Posted on: Friday, March 28, 2008 at 4:36 PM
Message: Works perfect!

Thanks,
Slobo

Subject: Problem when i will use Two pages.
Posted by: anildesai (view profile)
Posted on: Saturday, April 26, 2008 at 4:06 AM
Message: Here i have to pages first is Post.aspx and second is NewPost.aspx.

I write this rules for both pages.

<rewriteRules>
<rule source="(\w+)/(\w+)/" destination="NewPost.aspx?Name=$1&Age=$2"/>
<rule source="(\d+)/(\d+)/(\d+)/" destination="Post.aspx?Year=$1&Month=$2&Day=$3"/>
<rule source="(.+)/Default.aspx" destination="Default.aspx?Folder=$1"/>
</rewriteRules>

Here i m calling Post.aspx page by..
<li><a href="<% = ResolveUrl("~/2000/01/01/") %>">Date in the URL 1</a></li>


and calling NewPost.aspx page by..
<li><a href="<% = ResolveUrl("~/sdfsdf/kkkkkkk/") %>">Student Information</a></li>

Here problem is only NewPost.aspx page is call for both above link..
I want to call Post.aspx ...

thanks.

Subject: Problem when i will use Two pages.
Posted by: anildesai (view profile)
Posted on: Saturday, April 26, 2008 at 4:19 AM
Message: Here i have to pages first is Post.aspx and second is NewPost.aspx.

I write this rules for both pages.

<rewriteRules>
<rule source="(\w+)/(\w+)/" destination="NewPost.aspx?Name=$1&Age=$2"/>
<rule source="(\d+)/(\d+)/(\d+)/" destination="Post.aspx?Year=$1&Month=$2&Day=$3"/>
<rule source="(.+)/Default.aspx" destination="Default.aspx?Folder=$1"/>
</rewriteRules>

Here i m calling Post.aspx page by..
<li><a href="<% = ResolveUrl("~/2000/01/01/") %>">Date in the URL 1</a></li>


and calling NewPost.aspx page by..
<li><a href="<% = ResolveUrl("~/sdfsdf/kkkkkkk/") %>">Student Information</a></li>

Here problem is only NewPost.aspx page is call for both above link..
I want to call Post.aspx ...

thanks.

Subject: How to access the query string parameters
Posted by: hellosibba (view profile)
Posted on: Tuesday, April 29, 2008 at 9:30 PM
Message: How do i fetch the values of query string.. say i put the id in name value pair.
Actual URL : ~/Tag.aspx?id=5
Displayed Virtual URL :~/tag/5.html
I have used rule to map ~/tag/5.html to ~/Tag.aspx?id=5
and the page is opening.

The virtual URL is mapped to actual page.
I got the issue where hot to get the Id=5.
Do i need to parse the entire URL, which can be devastating. Neither i am getting in path info.
Is there any place where i'll get the parameters in some name value collection....

Information Requested!!!!
Thanks in advance.

Subject: throws a 404 exception
Posted by: saumya (view profile)
Posted on: Thursday, July 10, 2008 at 7:04 PM
Message: The article is great
I tried the same code and it works on ASP.net development server but it does not work on IIS

Ex it works on http://locahost:18345/web/default.aspx
but it does not work on
http://localhost/default.aspx

Please advice
Thanks

Subject: throws a 404 exception
Posted by: saumya (view profile)
Posted on: Thursday, July 10, 2008 at 7:26 PM
Message: http://localhost/ThisIsATest/Default.aspx
cannot be found server/application error , i have unchecked the check file exists box

Subject: Please Help Me
Posted by: raj_v15 (view profile)
Posted on: Thursday, July 31, 2008 at 6:37 AM
Message: Hi,

I have a link like the one below:

http://localhost:2243/magicmoments/ViewAlbum.aspx?aid=1909087d-69c3-4970-909d-31d5e9fb9543

now i want to display it as

http://localhost:2243/magicmoments/1909087d-69c3-4970-909d-31d5e9fb9543

can you help me what the rule should be for this.
Thanks in advance.

Subject: Deployment
Posted by: jabailo (view profile)
Posted on: Tuesday, August 12, 2008 at 4:22 PM
Message: How do I deploy this application to another machine?

Assuming that I do not compile this on the target machine:

Into what directory do I copy the .dll?

Do I add to the global assembly cache? Or run regsvr32?

How do I get to the point of being able to register the module in web.config?

Subject: Deployment
Posted by: jabailo (view profile)
Posted on: Tuesday, August 12, 2008 at 4:39 PM
Message: How do I deploy this application to another machine?

Assuming that I do not compile this on the target machine:

Into what directory do I copy the .dll?

Do I add to the global assembly cache? Or run regsvr32?

How do I get to the point of being able to register the module in web.config?

Subject: Windows server 2003
Posted by: sudheshna (view profile)
Posted on: Wednesday, August 13, 2008 at 3:45 AM
Message:
The example given is not working on windows server 2003. Please let me know if there is any solution for this.

Thanks

Subject: Cannot Run as Website, only Virtual Directory
Posted by: jabailo (view profile)
Posted on: Wednesday, August 13, 2008 at 12:47 PM
Message: I was able to publish the Release code to a virtual directory on a remote server. After setting the wildcard filter to aspnet_isapi.dll the same website worked fine.

However, if I try to run it as it's own website, with its own IP address and do exactly the same thing, I get the 404 error!

In fact I made a virtual directory in the website, and pointed it to the same code, then made the isapi change, and it worked as well!

But I cannot run it as the top level of the website.

Can you suggest why this might happen?

Subject: This solution is NOT recommended. Use urlrewriter.net
Posted by: SandeepKumar (view profile)
Posted on: Thursday, August 14, 2008 at 4:10 AM
Message: This thing is not working in IIS 6 Win2K3 website.
Me and my team wasted lots of time using this, and found this UrlRewriter.NET.

UrlRewriter.NET is an open source solution which works with Win2K, Win2K3 and WinXP; and compatible with ASP.NET 1.1 and 2.

It has good regular expression support and lots of other features.

Please have a look, http://urlrewriter.net/index.php/support

For ASP.NET 3.5 check this article by scottgu http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx


Subject: Works good...only as vdir
Posted by: jabailo (view profile)
Posted on: Saturday, August 16, 2008 at 11:01 AM
Message: This solution works perfectly -- but only as a vdir. I'm suspecting there's a bug in configuring the root (website) level wildcard mappings in IIS 6.0.

I am hoping someone will respond to my challenge on this...

Subject: can you help me
Posted by: NghiaOi (view profile)
Posted on: Tuesday, August 19, 2008 at 1:32 AM
Message: i uesd asp.net 2005 rewrite url

runing: http://localhost:1458/Milk/About/

don't runing: http://localhost/Milk/About/

Subject: Postback problem
Posted by: abhishek1985 (view profile)
Posted on: Wednesday, September 10, 2008 at 3:08 AM
Message: If I am trying to postback Post.aspx page at that time URL in my Address bar is http://localhost:2748/Web/2001/12/24/

Than its thrown error like below

The HTTP verb POST used to access path '/Web/2001/12/24' is not allowed.

Can you please help me in this


Subject: Url Rewriting
Posted by: ankush_lee (view profile)
Posted on: Friday, September 19, 2008 at 1:34 PM
Message: Hi,

The code seems to be perfect, i have tried the code in my application & it seems to working properly. All what i want to know is how to redirect to the page for which i have set rules in web.config... I am unable to get the way for that. Can any one help for the same.

Thanks in advance

Subject: postback problem
Posted by: vaib (view profile)
Posted on: Thursday, September 25, 2008 at 9:35 AM
Message: Hi,
Thanks for write this code.This is perfect code for url rewriting.I try this.This work perfectly and rewrite url properly.But this create problem if I click on any button,This is not understand postback and on every page postback it generate new request,result of this my button click event not fired.
If any one know solution of this.Please help me .This is very urjent.

Thanks

Subject: only works with built in visual studio web server - not IIS
Posted by: niico (view profile)
Posted on: Saturday, October 04, 2008 at 12:31 AM
Message: hi

great article thanks.

I can get it to work from within the visual studio web server - but in IIS only the simple directory example exists.

Ive added .* to mapping - but still nothing.


Thanks!

Subject: update
Posted by: niico (view profile)
Posted on: Saturday, October 04, 2008 at 1:01 PM
Message: hi

further to my post above:

i also cant get either example to work on the webserver (windows server 2003R2) - ive followed the IIS 6 instructions to let the aspnet_isapi.dll intercept everything with no file extension.

please help?

Subject: Google indexing
Posted by: denniswong288 (view profile)
Posted on: Monday, October 20, 2008 at 7:55 PM
Message: Hi,

I'm using urlrewriting.net for my site's URLRewriting.

Was wondering if Google indexes pages using urlrewriting.net? or is this all a hype?

The thing is I've seen numerous posts that Google does not index pages using "urlrewriter.net".
However, I've not seen any regarding "urlrewriting.net".

Please note that these are 2 separate UrlRewriting solutions from 2 different teams/companies.

Thanks!

Subject: URL Rewriting Example
Posted by: DotNetGuts (view profile)
Posted on: Wednesday, October 22, 2008 at 11:17 AM
Message: Your article is good, but I have describe some simple and easiest way to perform URL Rewriting

http://dotnetguts.blogspot.com/2008/07/url-rewriting-with-urlrewriternet.html

Subject: Native Url Mapping
Posted by: senthil (view profile)
Posted on: Friday, October 31, 2008 at 1:11 AM
Message: Hi,
Hope you are fine. I am very strange to ASP.NET. I have a query that how to implement URL rewriting, when my project hosted in Local IIS server?. Because i had done Native URL mapping as you said. But it succeeded only when i am working local connection ( I meant when the file exist in System drive ). When i want to implement the same in IIS server, it doesn't work. What is the solution?

Subject: Native Url Mapping
Posted by: senthil (view profile)
Posted on: Friday, October 31, 2008 at 1:15 AM
Message: The error says "The page cannot be found"

Subject: IIS6 Root Fix
Posted by: valmont33 (view profile)
Posted on: Wednesday, November 26, 2008 at 6:47 PM
Message: If you are experiencing generic 404's when running your site from the root (http://localhost/page.aspx) or on a live shared server please make the following change to the original code.

File: RewriteModuleSectionHandler.cs
Line: 36
Orinial:
RewriteBase = HttpContext.Current.Request.ApplicationPath + "/";

Change To:
if (!HttpContext.Current.Request.ApplicationPath.EndsWith("/"))
{
_RewriteBase = HttpContext.Current.Request.ApplicationPath + "/";
}

Subject: iis 7
Posted by: cooldev (view profile)
Posted on: Sunday, December 28, 2008 at 10:28 PM
Message: Guys,

Great article its working fine on IIS 5 and IIS 6.Any ideas how to make it work on IIS 7.I am getting page not found error when i deploy my appication on IIS 7.any ideas..pls help

Subject: Not working at Live server
Posted by: den2005 (view profile)
Posted on: Thursday, February 12, 2009 at 9:02 PM
Message: Hi,

Anybody encountered this, I followed what is written here working at my local pc when I deployed/published it at Live server, url rewriting won'r work..Error 404?? Anybody how to fixed this, Live server using IIS 6.

Please help..Thanks

Subject: What should be the Start URL for this sample app
Posted by: mayuresh (view profile)
Posted on: Tuesday, March 10, 2009 at 10:10 AM
Message: I have configured the application to have the start URL as -
http://localhost/RewriteModule/2006/12/10/ , but the HttpContext.Current.Request.Path is returning -
http://localhost/RewriteModule/2006/12/10/Default.aspx

The regular expression in the web.config doesn't match the path returned. Please help

Subject: url rewriting is working in local but it is not working in server any body plz
Posted by: shekhar.kandregula (view profile)
Posted on: Monday, March 16, 2009 at 4:46 AM
Message: Hi friends,
i have used this code recently ,it is working in localhost but it is not working when i upload at the server.Can anybody plz tell me the solution,its very urgent.

with thanks®ards,
sekhar

Subject: hi friends can any body tell the rule which will work in server
Posted by: shekhar.kandregula (view profile)
Posted on: Monday, March 16, 2009 at 4:50 AM
Message: hi friends can any body tell the rule which will work in server.

i used below rule for url rewriting ...

<rule source="(.+).blogs/(.+).aspx" destination="blogsdisplay.aspx?name=$1&title=$2"/>

but it is working in local but when im upload at server it ,it shows 404 error.

Subject: Not working in server
Posted by: debayan (view profile)
Posted on: Tuesday, March 24, 2009 at 10:12 AM
Message: Hi friends , using the rewriting module,it work fine in local ,but it not work in server. Is any body has the solutions for it.
Thank in advance.

Subject: Rewrite hompage
Posted by: thaiduong28 (view profile)
Posted on: Tuesday, May 12, 2009 at 10:47 PM
Message: i want to rewrite default.aspx
like
http://localhost:3959/Web/Default.aspx
to http://localhost:3959/Web/Home

when website starting

Subject: IIS5.1
Posted by: techie579 (view profile)
Posted on: Thursday, June 18, 2009 at 3:20 AM
Message: Dear Sir

I have tried the code. It's nice working fine when i run the application from the file system. But if i try to run it from the IIS5.1 it's not working.Why it's not working. What the necessary things i have to do. Please help me to find the solution.

Thanks

Subject: URL Rewriting in IIS5.1
Posted by: techie579 (view profile)
Posted on: Saturday, June 20, 2009 at 2:47 AM
Message: Dear Sir

When i host your files under C:\inetpub\wwwroot\TestURL it's working. The URL
http://localhost/TestURL/ThisIsATest/Default.aspx
is working without raising any error.

But when i host the same files under
C:\inetpub\wwwroot it's not working.
The URL http://localhost/ displays default.aspx
page .
The URL http://localhost/ThisIsATest/Default.aspx
displays The resource cannot be found. What i hve to do inorder to solve this. Please help me. Please mail the solution to santosh579@gmail.com
This is very urgent. We want to host it on the live server

Thanks

Subject: Facing problem while deploying site on iis
Posted by: shaileshbakadia (view profile)
Posted on: Tuesday, July 21, 2009 at 10:18 AM
Message: Dear Gaidar Magdanurov

I am getting problem of 404 while deploying your url rewritting site its running perfect in local but when i try to deploy it on same machin on IIS with windows 2003 then it gives us error of 404 page not found. I am using version 5.2(Build 3790.srv03_sp_rtm.070216-1710: Service Pack 2).
Can you or any body help me to resolved this issue. this is working very fine in local but giving problem at time of deploying. you can email me on shailesh.bakadia@hotmail.com

Thanks


Shailesh Bakadia
shailesh.bakadia@hotmail.com

Subject: problem
Posted by: santhosh047 (view profile)
Posted on: Monday, August 10, 2009 at 5:15 AM
Message: when i configure in to iis i have to type
http://localhost/web/default.aspx
its works fine but when i type http://localhost/web
shows error 404.
what is the solution for this to access default.aspx directly without typing the file name

santhosh kumar.G

Subject: URL Masking
Posted by: manu4ever (view profile)
Posted on: Thursday, August 20, 2009 at 2:50 PM
Message: Hi,
Could you please help me on the below.
How can I mask the URl, lets say from
http://abc.ijk/xyz to http://xyz

Please reply me.
Regards,
Manoj.

Subject: More than one level of URL not working
Posted by: elitekrishnan (view profile)
Posted on: Wednesday, September 16, 2009 at 10:33 PM
Message: Hi,

This URL rewriting is working fine for the one level of url structure, when we go to more than one level, it is not working.
Example: If i am in 3rd level means, then it is taking the second level url's page. Please suggest me to go for multi level url struucture.

Please reply me.
regards,
Krishnan

Subject: More than one level of URL not working
Posted by: elitekrishnan (view profile)
Posted on: Wednesday, September 16, 2009 at 11:01 PM
Message: Hi,

This URL rewriting is working fine for the one level of url structure, when we go to more than one level, it is not working.
Example: If i am in 3rd level means, then it is taking the second level url's page. Please suggest me to go for multi level url struucture.

Please reply me.
regards,
Krishnan

Subject: This is artucle is not working for extension less urls
Posted by: Bhaskar Munukuri (view profile)
Posted on: Wednesday, September 16, 2009 at 11:52 PM
Message: Hi,

This urlrewriting is not working for extensionless url. i was devoloped website in IIS6 and WindowsXp.
This urlrewritng is not working.

Please suggest me to devlope Extensionless url structure.

Please reply me.
Regards
Bhaskar

Subject: More than one level of URL not working
Posted by: elitekrishnan (view profile)
Posted on: Thursday, September 17, 2009 at 2:22 AM
Message: Hi,

This URL rewriting is working fine for the one level of url structure, when we go to more than one level, it is not working.
Example: If i am in 3rd level means, then it is taking the second level url's page. Please suggest me to go for multi level url struucture.

Please reply me.
regards,
Krishnan

Subject: configuration error
Posted by: janaki (view profile)
Posted on: Thursday, September 24, 2009 at 4:39 AM
Message: i have used the same file , and i have add that referrences in BIN. Now , in Web.config if i write <modulesSection> then it gives me error , like Unorganized modulesSection in web.config file.

Subject: Help Needed in URL Rewritting
Posted by: fewlines4biju (view profile)
Posted on: Tuesday, October 13, 2009 at 3:36 PM
Message: Hi Gaidar Magdanurov,
Really this is a very nice article for URL rewritting in asp.net.

Actually I have my own web site http://www.fewlines4biju.com . Here I am showing list of articles in gridview. And one user clicks on a particular link then it opes of page like http://www.fewlines4biju.com/TopicDetails.aspx?TopicID=34

I want to implement URL rewritng so that the URL will come like http://www.fewlines4biju.com/How-to-implement-urlrewritting.aspx rather than with query string parameter. And this titlewill come from the Title Field in the database. I hope you would help me like what will be the rules for this and all. waiting for your reply.

Subject: Not wroking on Live Server (The page cannot be found)
Posted by: vish007 (view profile)
Posted on: Monday, October 26, 2009 at 1:57 PM
Message: Dear Gaidar Magdanurov,

This is really very good article but the problem is its working good in localhost but on live server its not working, its showing "The page cannot be found"

so which type of setting i have to do? Pls, guide me

Thanks

Subject: I Translate your article into Chinese
Posted by: wuxs (view profile)
Posted on: Thursday, November 26, 2009 at 3:22 PM
Message: 未经您的许可,我将您的这篇文章翻译为中文,并放在下面的地方,如果您有什么意见,或版权方面的要求,请给我发邮件:
wwxs@163.com
下面是译文地址:
http://www.souty.cn/Admin/Knowledges/ShowKnowledge.aspx?id=d3c92130-4479-492c-9536-2f141a6557fd

Subject: fix for working locally but not on the server
Posted by: lostapache (view profile)
Posted on: Monday, January 11, 2010 at 1:36 PM
Message: Like many of you it worked locally when using a virtual directory but not on the server.

You need to change a line in RewriteModuleSectionHandler.cs

In the file:
_RewriteBase = HttpContext.Current.Request.ApplicationPath + "/";

Change to:
_RewriteBase = HttpContext.Current.Request.ApplicationPath;

Use the new dll in your application and it will work on the root.

Cheers

Subject: getting it to work on root and virtual dir
Posted by: lostapache (view profile)
Posted on: Monday, January 11, 2010 at 1:42 PM
Message: To get it to work on both the root and a virtual directory do the below changes in file RewriteModuleSectionHandler.cs

Original Code:
_RewriteBase = HttpContext.Current.Request.ApplicationPath + "/";

Change To:
if (HttpContext.Current.Request.ApplicationPath.EndsWith("/"))
{
_RewriteBase = HttpContext.Current.Request.ApplicationPath;
}
else
{
_RewriteBase = HttpContext.Current.Request.ApplicationPath + "/";
}

Cheers

Subject: Unable to call usercontrol link button click
Posted by: amitkumarrawat (view profile)
Posted on: Thursday, January 14, 2010 at 5:08 AM
Message: I have a user control. In which there is signout button. When i click on signout. Then Sign Out button event not fired. Simply page refresh. Please help. :( :(

Subject: Unable to call usercontrol link button click
Posted by: amitkumarrawat (view profile)
Posted on: Thursday, January 14, 2010 at 5:16 AM
Message: I have a user control. In which there is signout button. When i click on signout. Then Sign Out button event not fired. Simply page refresh. Please help. :( :(

Subject: do not work with godaddy
Posted by: hareshambaliya (view profile)
Posted on: Friday, January 22, 2010 at 3:00 AM
Message: Hi,
Your article is nice.
but I have problem with UrlRewriting. I got error on server. I am using IIS7 with shared hosting in godaddy.
I got error page do not found. Please help me its urgent.

Subject: Great Work
Posted by: HarrySgss (view profile)
Posted on: Thursday, February 11, 2010 at 3:22 AM
Message: This is very nicely explained article on URL rewriting.

Subject: Very nice
Posted by: murraharri (view profile)
Posted on: Wednesday, March 10, 2010 at 9:48 AM
Message:
thanks a lot.

Can i use your dll in the source in my code for url rewriting


Subject: How to write rule in web.config file for the given url?
Posted by: dmaulik142 (view profile)
Posted on: Thursday, March 25, 2010 at 3:22 AM
Message: Hi Friend

Excellent work u have done.

I have url as below.
http://www.levinsonjewelers.com/fine_jewelry.aspx?menu=4&catid=5&catsubid=2&productid=352&page=2

Now I want to display above url as below into addressbar.

http://www.levinsonjewelers.com/fine_jewelry/bracelets_whitegold.aspx

Please let me know how to write in web config file for above url?

Thanks
Maulik

Subject: Good article
Posted by: himabindu (view profile)
Posted on: Friday, April 09, 2010 at 5:33 AM
Message: Hi Gaidar Magdanurov,

U have done an excellent work for this article.
Congrats and thnx.

I need some help

I have an url like www.shopmate.com/Jewellery/Index.aspx

Now i need to change it as
www.shopmate.com/Shop1/Index.aspx

That means
the folder name Jewellery has to be changed to Shop1.

How can i do this........?

Please let me know about this....

Thanks in advance

Subject: Issue regarding IIS7.0
Posted by: Tanmaydeveloper (view profile)
Posted on: Thursday, May 13, 2010 at 1:09 AM
Message: Dear Gaidar Magdanurov,
this is a great article of Url Rewriting I have also implemented in my solution on .net 3.5 plat form and it is running fine but its published code is not working on IIS 7.0 and IIS 5

Please give me some description to work out

thanks
Tanmay Srivastava
Tanmaydeveloper@gmail.com

Subject: errr i getting in iis 7
Posted by: Tanmaydeveloper (view profile)
Posted on: Thursday, May 13, 2010 at 1:44 AM
Message: HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Subject: please help
Posted by: nazojan (view profile)
Posted on: Tuesday, June 15, 2010 at 1:33 PM
Message: HI everyone,
I am hosting a site on 1and1.com, this URL rewriting app working very good on my localhost but when i try to host it on 1and1.com server I get an error that path not found, the Virtual Folders exemple is working fine but the othe exemple wtih Post.aspx to past the query strings they not working and I am geting the error message Error 404: NOT FOUND! I see some other people have a complaint about this above. Please help if anyone knows any thing about this.

thnks,
Naz
webncyber@hotmail.com

Subject: Not Working online
Posted by: swathinithya (view profile)
Posted on: Tuesday, July 13, 2010 at 1:58 AM
Message: when i have tried RewriteModule for url writing its working offline(Localhost) but when i have uploaded on webserver(online) its not working.........Above i have seen the same problem even some are facing if you got the solution please do help me out.....thanks in advance .

Subject: What about this scenario
Posted by: kirkdm (view profile)
Posted on: Wednesday, July 14, 2010 at 2:13 PM
Message: How do you implement a url rewrite for querystring that has spaces and you want the url to rewrite it with the "-" character in between each word for example

http://www.mysite.com/some-text-here/default.aspx and
http://www.mysite.com/article.aspx?id=some text here

Subject: VB.Net Conversion
Posted by: daCodez (view profile)
Posted on: Friday, September 03, 2010 at 12:24 PM
Message: How would i convert the following to VB.NET anyone know?

context.BeginRequest += New EventHandler(RewriteModule_BeginRequest)
context.PreRequestHandlerExecute += New EventHandler(RewriteModule_PreRequestHandlerExecute)

Subject: Answer
Posted by: daCodez (view profile)
Posted on: Friday, September 03, 2010 at 1:42 PM
Message: Hey all I answered my own question. For those who are interested in the answer it is:
AddHandler context.BeginRequest, AddressOf Me.RewriteModule_BeginRequest
AddHandler context.PreRequestHandlerExecute, AddressOf Me.RewriteModule_PreRequestHandlerExecute

Subject: Very good artical.Need some more info
Posted by: Pankaj Mahajan (view profile)
Posted on: Tuesday, February 15, 2011 at 6:57 AM
Message: The given artical is very helpfull because it shows complete code and iis setting.
Will you please suggest these setting for IIS 7.5 (window server 2008 R2).
Also,these setting working fine in my case except root url.so can you please provide more information regarding this.
Thanks

Subject: Problem after using rewrite Url
Posted by: Munna.bhakta1001 (view profile)
Posted on: Saturday, February 26, 2011 at 5:00 AM
Message: hi i am using this url rewriter module but
after using this module.
my page load multipal time and data is going to loss
.
I not understand how can do.
Url formate is
<rule source="CarReviewByExpertDetails/(.+)/(.+)" destination="CarExReadMore.aspx?Manu_Name=$1&Mod_Name=$2"/>

Subject: HttpContext.Current.RewritePath bug?
Posted by: Justin1978 (view profile)
Posted on: Thursday, April 28, 2011 at 5:21 AM
Message: Nice article, works fine except for one thing:

I'm directing from a page1?foo=bar to a page2?hello=world.

Your example joins te querystrings and uses HttpContext.Current.RewritePath to rewrite the path and the querystring. This works; the querystring now contains foo and hello (I use a foreach to loop trough HttpContext.Current.Request.QueryString)

But: on the page that is redirected to, page2?hello=world, the HttpContext.Current.Request.QueryString only contains the query-variables from the request-uri, in this case only foo. Where's hello?

It appears that it is overwritten somewhere between the execution of the code in RewriteModule and the code on the redirectpage. Is this a bug? I'm breaking my head on how to solve this.

Subject: Regular Expression
Posted by: Bhavin (view profile)
Posted on: Saturday, April 30, 2011 at 6:13 AM
Message: Hello Sir,

i am trying url rewriting in my application,i have added your code reference in my project and also done all web.config file setting also.

My original url is below

http://localhost:50820/cmgmt_28_04_2011/Quotes/mypage.aspx?catid=0

in that whole url i have to make my url like below

http://localhost:50820/cmgmt_28_04_2011/Quotes/General
how can i do it.i have tried through your given test project as a reference but its give the error like "Resource can not be found."
can you please guide me in that.
my web config rules like below
<modulesSection>
<rewriteModule>
<rewriteOn>true</rewriteOn>
<rewriteRules>
<rule source="(\d+)" destination="mypage.aspx?catid=$1"/>
</rewriteRules>
</rewriteModule>
</modulesSection>
if any error in that can you correct it and this code also working in live server if i ill upload it any setting for that also.
waiting for your response as soon as early.

Regards,
Bhavin

Subject: this is not working withour virtual directory
Posted by: Nidhi Thakrar (view profile)
Posted on: Tuesday, May 03, 2011 at 10:44 AM
Message: Hello,
It's really good article.
But i am facing one problem.
its working fine with virtual directory.
But when i use this module without virtual directory ( i mean on direct wwwroot folder) its not working. Please guide what can i do?

Subject: url rewriting issues
Posted by: tintu.augustine (view profile)
Posted on: Tuesday, May 10, 2011 at 4:33 AM
Message: i tried to implement this method in my site.url is changing but the page is not loading.showing
Like this

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /hemi-sync/About_us

can u please help me.

Subject: Rewrite with Server.Transfer method
Posted by: panda.dodt (view profile)
Posted on: Saturday, January 28, 2012 at 8:44 AM
Message: hi my friend.
your idea is verry good, but i think it is not complete.i tested it, that's ok. but when i use Server.Transfer("url") then it can not rewrite or wrong rewrite.
so do you have a idea?

Subject: Problem Regarding Url Rewriting
Posted by: anis (view profile)
Posted on: Friday, April 20, 2012 at 7:30 AM
Message: I have a problem in URL rewriting that its running properly in localhost but when i hit the default page in the server its not working.

Plz Solve my Problem

Subject: ASP.NET 4 users should use Url Routing
Posted by: gaidar (view profile)
Posted on: Sunday, July 01, 2012 at 10:01 AM
Message: Hello dear friends,

It's been ages since I wrote the article and I am still getting questions and comments on the solution. Though, in case you use ASP.NET 4 I propose to use in-built Url Rounting - http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx

Subject: URL REDIRECTION
Posted by: anilbabu.m (view profile)
Posted on: Thursday, August 02, 2012 at 6:54 PM
Message: What is URL REDIRECTION?How can i use this concept in my .net?
my task is i have generated one url like this "http://example.com/"
I am passing one pearameter like "http://example.com/Empno=1"
I want to display Ename in Database table that corresponding "Empno"
plz Help me Give me one simple example

I am new this concepts
plz Help me send source code to my mailID:anilbabu.m@hotmail.com

Subject: Not working On Server
Posted by: abhitheflame (view profile)
Posted on: Friday, March 08, 2013 at 5:59 AM
Message: Your code working properly at local machine but not on a server. I have configure the isapi in iis 6.0 but still not worked.Please give me a solution.

Subject: Is not match
Posted by: changtotbung1105 (view profile)
Posted on: Sunday, April 21, 2013 at 8:26 PM
Message: Hi everybody! the commend: if (match.Success) is alway false! how can you help me?

Subject: How can I create rules from code behined and then add that rules in config file
Posted by: abhitheflame (view profile)
Posted on: Saturday, August 17, 2013 at 1:08 AM
Message: I want to create some rules dynamically from my code behined. Is there any way to achieve this/.

Subject: How can I create rules from code behined and then add that rules in config file
Posted by: abhitheflame (view profile)
Posted on: Saturday, August 17, 2013 at 1:15 AM
Message: I want to create some rules dynamically from my code behined. Is there any way to achieve this/.

Subject: IIS 6 Website Solved Problem
Posted by: amir490 (view profile)
Posted on: Saturday, October 19, 2013 at 11:48 AM
Message: Hi
Thanks For your solution
i found Problem On the URL rewriting problem in website but this worked on virdir
the problem is in RewriteModuleSectionHandler.cs

_RewriteBase = HttpContext.Current.Request.ApplicationPath + "/";

and this section

this part of the code just return in virtual directory but in the website return empty

you can use http://michaelkappel.com/examples/CSharp/Helper/ApplicationPath.htm

for return ApplicationPath()

and fix it to

_RewriteBase = MichaelKappel.Net.CSharp.Helper.ApplicationPath() + "/";

With the hope of success


Subject: Dedicated .net Programmer
Posted by: alfredmarshall (view profile)
Posted on: Tuesday, October 29, 2013 at 3:10 AM
Message: Hello,i have gone through your article and it is very good and impressive you have maintained it very properly and after studying the matter very well. Thanking you

Subject: Rewrite URL
Posted by: ashishr (view profile)
Posted on: Friday, January 10, 2014 at 12:33 AM
Message: I've URLs in my website and which are using query string values For example: http://foo.com/xyzPage.aspx?barvalue=yehaa
to
http://yehaa.foo.com/
Please suggest how it can be accomplished without actually creating subdomains on server ..
I've IIS 7.5 installed on server machine and using Asp.net 4.0.

Subject: Rewrite URL
Posted by: ashishr (view profile)
Posted on: Friday, January 10, 2014 at 12:37 AM
Message: I've URLs in my website and which are using query string values For example: http://foo.com/xyzPage.aspx?barvalue=yehaa
to
http://yehaa.foo.com/
Please suggest how it can be accomplished without actually creating subdomains on server ..
I've IIS 7.5 installed on server machine and using Asp.net 4.0.

Subject: Rewrite URL
Posted by: ashishr (view profile)
Posted on: Friday, January 10, 2014 at 1:12 AM
Message: I've URLs in my website and which are using query string values For example: http://foo.com/xyzPage.aspx?barvalue=yehaa
to
http://yehaa.foo.com/
Please suggest how it can be accomplished without actually creating subdomains on server ..
I've IIS 7.5 installed on server machine and using Asp.net 4.0.

 

Top Rated

Acceptance Testing with FitNesse: Multiplicities and Comparisons
 FitNesse is one of the most popular tools for unit testing since it is designed with a Wiki-style... Read more...

Acceptance Testing with FitNesse: Symbols, Variables and Code-behind Styles
 Although FitNesse can be used as a generic automated testing tool for both applications and databases,... Read more...

Acceptance Testing with FitNesse: Documentation and Infrastructure
 FitNesse is a popular general-purpose wiki-based framework for writing acceptance tests for software... Read more...

TortoiseSVN and Subversion Cookbook Part 11: Subversion and Oracle
 It is only recently that the tools have existed to make source-control easy for database developers.... Read more...

TortoiseSVN and Subversion Cookbook Part 10: Extending the reach of Subversion
 Subversion provides a good way of source-controlling a database, but many operations are best done from... Read more...

Most Viewed

A Complete URL Rewriting Solution for ASP.NET 2.0
 Ever wondered whether it's possible to create neater URLS, free of bulky Query String parameters?... Read more...

Visual Studio Setup - projects and custom actions
 This article describes the kinds of custom actions that can be used in your Visual Studio setup project. Read more...

.NET Application Architecture: the Data Access Layer
 Find out how to design a robust data access layer for your .NET applications. Read more...

Calling Cross Domain Web Services in AJAX
 The latest craze for mashups involves making cross-domain calls to Web Services from APIs made publicly... Read more...

Web Parts in ASP.NET 2.0
 Most Web Parts implementations allow users to create a single portal page where they can personalize... Read more...

Why Join

Over 400,000 Microsoft professionals subscribe to the Simple-Talk technical journal. Join today, it's fast, simple, free and secure.