A Complete URL Rewriting Solution for ASP.NET 2.0

来源:互联网 发布:聊天记录数据恢复 编辑:程序博客网 时间:2024/04/29 09:06
A Complete URL Rewriting Solution for ASP.NET 2.0
01 March 2007
by Gaidar Magdanurov

Thisarticle describes a complete solution for URL rewriting in ASP.NET 2.0.The solution uses regular expressions to specify rewriting rules andresolves possible difficulties with postback from pages accessed viavirtual 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, neatURLs to monstrous addresses packed with difficult to comprehend querystring parameters. From time to time, being able to remember and typein a concise URL is less time-consuming than adding the page to abrowser's favorites only to access later. Again, when access to abrowser's favorites is unavailable, it can be more convenient to typein the URL of a page on the browser address bar, without having toremember a few keywords and type them into a search engine in order tofind 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 datefor which some blog engines should show available postings. The secondURL contains this information in the address, giving the user a clearidea of what he or she is going to see. The second address also allowsthe 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 pagesfrom one directory to another. Let us suppose that support informationwas 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 newlocation. This issue can be resolved by adding simple dummy pagescontaining calls to Response.Redirect(new location).However, what if there are hundreds of moved pages all over theapplication directory? The web project will soon contain too manyuseless pages that have the sole purpose of redirecting users to a newlocation.

Enter URL rewriting, which allows a developer to move pages betweenvirtual directories just by editing a configuration file. In this way,the developer can separate the physical structure of the website fromthe 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 staticURLs within a web application. It is possible to map old URLs to newones in web.config without writing any lines of code. To use URLmapping, 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 beenmoved to other locations, but it is completely unsuitable where thereare dozens of re-located pages, or where a really neat URL needs to becreated.

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="http://www.simple-talk.com/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 inone mapping rule. The best solution is to use Regular Expressions (foroverview see Wikipedia and for implementation in .NET see MSDN),but an ASP.NET 2.0 mapping does not support regular expressions. Wetherefore 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 createreusable and easily configurable modules, so the obvious decision is tocreate an HTTP Module (for details on HTTP Modules see MSDN Magazine)and implement it as an individual assembly. To make this assembly aseasy to use as possible, we need to implement the ability to configurethe rewrite engine and specify rules in a web.config file.

During the development process we need to be able to turn therewriting module on or off (for example if you have a bug that isdifficult to catch, and which may have been caused by incorrectrewriting rules). There should, therefore, be an option in therewriting 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 therewriting module is that it should be possible to use 'virtual' URLswith 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 passedvia 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.Webassembly, as we want this library to be used within an ASP.NETapplication and we also want to implement some web-specific functionsat 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 importantthat you clearly distinguish parameters that were passed via a querystring from parameters that were passed as virtual directories. Usingthe 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 staticmethod 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.configfile. Secondly, we need to check the actual URL against the rules and,if necessary, do some rewriting so that the appropriate page isexecuted.

We create an HttpModule:

class RewriteModule : IHttpModule
{

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

{}

}

When adding the RewriteModule_BeginRequestmethod that will process the rules against the given URL, we need tocheck 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 therewriting module should handle a web form's postbacks and populate acollection of 'virtual path parameters'. In the given code you will notfind a part that does this task. Let's put 'virtual path parameters'aside for a moment. The main thing here is to handle postbackscorrectly.

If we run the code above and look through the HTML source of theASP.NET page for an action attribute of the form tag, we find that evena virtual URL action attribute contains a path to an actual ASP.NETpage. 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 RewriteContextwill be populated with actual parameters and a second URL rewritingwill be performed. The second rewriting is necessary to make ASP.NETbelieve it wants to use a virtual path in the action attribute of anHTML 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 RewriteModulewith pages other than .aspx, you should configure IIS to map requeststo pages with the desired extensions to ASP.NET runtime as described inthe next section.

IIS Configuration: using RewriteModule with extensions other than .aspx

To use a rewriting module with extensions other than .aspx (forexample, .html or .xml), you must configure IIS so that these fileextensions 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 andtype in an extension. You also need to specify a path to an ASP.NETISAPI 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 5on Windows XP you have only to map .* extension to the ASP.NET ISAPIextension. But for IIS 6 on Windows 2003 you have to do it in aslightly 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 forASP.NET that supports regular expressions-based URLs and pagepostbacks. This solution is easily implemented and gives users theability 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.configfile, whereupon you have all the power of regular expressions at yourdisposal 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 lookthrough the source code and example attached to this article. I believeyou'll find using the rewriting module a far more pleasant experience,than using the native URL mapping in ASP.NET 2.0.



This article has been viewed 106942 times.
Gaidar Magdanurov

Author profile: Gaidar Magdanurov

Gaidar,an MVP for Visual Basic, lives in Moscow. His primary job is scientificresearch in INEOS RAS. Gaidar also works as a softwaredeveloper/consultant and is editor-in-chief of the VBStreets web site,dedicated to Visual Basic and Microsoft .NET technologies. An activemember of the Russian GotDotNet community, Gaidar also enjoys speakingat user-group meetings. In his spare time, Gaidar likes playing theguitar, 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 174 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: Thereare many articles that pretend to address this topic, but this is thefirst 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!

Ihave followed your setup etc. and no matter what I try, IIS6 (Win2k3server) returns a 404 when I try to access the URL that needs to bere-written. For example:

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

butIIS always seems to return the generic 404 error page (“page ordirectory 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 forintegrated URL mapping functionality in ASP.NET. But I can answer - youhave to configure IIS web server to handle .* (all extensions) withASP.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,

Thanksfor your post. We have used your code in our project but we are facinga problem that its working fine in 5.1 but not working in 6.0. Pleasegive 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: Iwas able to get your code to work on my local development machine butwhen 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 byraising 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.
Iam not using and Regular expression comaparisons justblogs/derectory/default.aspx for the source and blogs/default.aspx forthe 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: Iwas able to get your code to work on my local development machine butwhen 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 byraising 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.
Iam not using and Regular expression comaparisons justblogs/derectory/default.aspx for the source and blogs/default.aspx forthe 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'sbecause when your web ap run in root url, theHttpContext.Current.Request.ApplicationPath will be "/", if you appendan "/" 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 upby ASP.NET. You're giving .NET processing duties that are normallyhandled by IIS. When a page loads, .NET isn't handling one page, it'shandling one page PLUS any number of .css, .js, .gif, .jpg, or .pngfiles. Multiply that by every page load of every user of every site onthe 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 onlyneeds to handle missing files, like "/MyVirtualPage/".

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

Nowlet's take it a step further to witness the destructive potential of asingle missing image. Let's say you have a master page (or a controlused on all pages), and it has an image tag pointing to an image thatno 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 thesame master page with the same missing image, so now you've got aninfinite 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 temporarilyunavailable. Please review the following URL and make sure that it isspelled 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: Agood article, although usability and maintainability are not goodreasons to consider rewrting your urls. A user experienced enough tomanipulate the flattened will be able to manipulate the dynamicversion. I also do not want users manipulating url's if i can help it.

Howeverrewriting your urls as meaningful textual phrases is a great idea, notjust 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.

Firstof all, most of the problems arise because of relative paths, so it isbetter to use paths starting from the root. Thus, you should use thefollowing 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?

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

As formapping .* to ASP.NET - I myself don't like the idea (maybe because I'mserved 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 notseen it before because I have been using this type of rewriting formore than 3 years now and never Google/Live/Yahoo and etc. forrewriting solutions...

As for this rule:

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

Yourregular 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 thefollowing 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 temporarilyunavailable. Please review the following URL and make sure that it isspelled 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: Itested it in local, and it runs well.But I upload DLL in a sharehosting, 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"
andwhen i use the "http://192.168.1.2/XYZ/mn.aspx" ,which is the IP of thesame machine, i could not access the pages, wherever the prior URLworks properly.
For this reason i am not getting access these pagesfrom other machines on the LAN and not from the internet (my server isconfigured as WEB server).
Plz solve my problem, i am not gettingany solution. I had seen this type of problem in this topic but did notget any solution from you. So, plz solve my problem as early aspossible.

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,
Ihave found the bug. I have used <base href="http://project/"> tagto overcome the problem of css,images rendering so URL rewriting is notworking and Request.path is changed. If I remove <base> css andimages 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: Thisis a fantastic solution. You don't know how hard I've tried to getother URL rewriting solutions working, and this one works perfectly forme. 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'vebeen trying it out but due to some reason if I create a file systembased website in VS2005, the redirection works. But when I create thewebsite in IIS and run it from VS2005, it doesn't break intoRewriteModule_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 therewriting. Thats meen when somebody do www.site.com/help its going tothe good place www.site.com/newsite/helpContext/help.aspx (somethinglike 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 theURL 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: Couldnot load file or assembly 'RewriteModule' or one of its dependencies.The system cannot find the file specified. (<drivename>:/Documents and Settings/<user name>/<foldername>/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: Iopen the "RewriteModule" with VS 2005 on Windows Vista. It's finewithout publishing it. When I publishing it to another site, I got
"HTTP Error 500.0 - Internal Server Error"

Irun 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 erroroccurred creating the configuration section handler formodulesSection/rewriteModule: Error while processing RewriteModuleconfiguration 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: ihave used the same DLL file , and i hava add that referrences in BIN.Now , in Web.config if i m write <modulesSection> then it givesme 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: itis not workin on thw live , like i wanthttp://www.roadtriphelper.com/locate/pune/ then it will display a mapof 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,
Firstof thanks for this ultimate program. Here i m using this tool for mywebsite and the site is online, But it is working too much slow. Ratherthan other sites are working too fast and i found the cause isweb.config Here i writes all rule for rewriting in web.config and itbecome too slow.


So please give me suggestion to improve thespeed for site and also the main problem of image path. i m includedbasic 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,

Yourcode work well, when I run with Microsoft Visual Studio Professional2005 on my local machine. Then I run this code on my Hosting, it didn'twork. And I ask my hosting he reply that your dll url rewrite did notwork.

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,

Pleasehelp me for your code. Because I use this code make URL Rewriting, Butit work only run with Visual Studio Professtional 2005. And I publishthis 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: Iwas able to publish the Release code to a virtual directory on a remoteserver. After setting the wildcard filter to aspnet_isapi.dll the samewebsite 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!

Infact I made a virtual directory in the website, and pointed it to thesame 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

ForASP.NET 3.5 check this article by scottguhttp://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: Thissolution works perfectly -- but only as a vdir. I'm suspecting there'sa bug in configuring the root (website) level wildcard mappings in IIS6.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,

Thecode 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 toredirect to the page for which i have set rules in web.config... I amunable 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 trythis.This work perfectly and rewrite url properly.But this createproblem if I click on any button,This is not understand postback and onevery page postback it generate new request,result of this my buttonclick 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:

ialso cant get either example to work on the webserver (windows server2003R2) - ive followed the IIS 6 instructions to let theaspnet_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: Google indexing Posted by: denniswong288 (view profile) Posted on: Monday, October 20, 2008 at 9:46 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 thathow to implement URL rewriting, when my project hosted in Local IISserver?. Because i had done Native URL mapping as you said. But itsucceeded only when i am working local connection ( I meant when thefile exist in System drive ). When i want to implement the same in IISserver, it doesn't work. What is the solution?
原创粉丝点击