URL rewrite path - doesnt redirect

I've followed the instructions in the related question. I have my web config ready. I'm following Approach 3 of this link
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

My "rewriter" section looks like this but when I bring up the page and go to that path, it doesnt rewrite it. It stays the same. What am I missing?

 <rewriter>
    <rewrite url="~/Arms/SignUp/Default2Try.aspx" to="~/Arms/SignUp/userSignUp" />
  </rewriter>
LVL 8
CamilliaAsked:
Who is Participating?
 
käµfm³d 👽Commented:
Yes, but shouldn't  putting this in webconfig
<rewriter>
    <rewrite url="~/user/(.+)" to="~/userinformation.aspx?id=$1" />
</rewriter>
but i want them to see http://www.mysite.com/user/12
No. Putting that in the web.config will not give you what you are looking for.
0
 
käµfm³d 👽Commented:
Just to be clear:  you understand what URL rewriting is, yes? You will not see "/Arms/Signup/userSignUp" in the browser; you will see "/Arms/SignUp/Default2Try.aspx". When your user goes to that page, the server will turn the incoming "/Arms/SignUp/Default2Try.aspx" into "/Arms/Signup/userSignUp".
0
 
CamilliaAuthor Commented:
Yes, but shouldnt i see this on my machine when I'm running the code??
"/Arms/Signup/userSignUp"

I should upload it to the server and test it??
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
käµfm³d 👽Commented:
Yes, but shouldnt i see this on my machine when I'm running the code??
I'm not entirely sure what you mean. If you mean you are running this in a browser on the same machine that is hosting the web site, the answer is no, you will not see it. If you mean will you see it in the log, I am not up to par on IIS' rewrite logging, but I would expect there to be some sort of log that records the rewrite taking place (I know mod_rewrite in Apache does this). If you can find the log for rewrites on your IIS server, I would expect the rewrite to be recorded there.
0
 
CamilliaAuthor Commented:
no, not talking about log.

 >>If you mean you are running this in a browser on the same machine that is hosting the web site, the answer is no, you will not see it.

Yes, that's what I'm talking about. I'm running it on my laptop by pressing F5 and looking at the URL...

So, I need to upload to web host server and then bring up the page? (i thnk so). I will try.
0
 
käµfm³d 👽Commented:
Rewriting does not change the link you see in the browser. You should make your links in your page reflect what you want the user to see (e.g. SEO-friendly links). Rewriting takes a user-friendly/SEO-friendly URL:


and turns it into a server-friendly/query-string-friendly URL:

0
 
käµfm³d 👽Commented:
Search engines won't index links that are of the format in the bottom example. This is why people use SEO (search-engine optimzed) links in their pages (the top example).
0
 
CamilliaAuthor Commented:
This is what I want (maybe i asked for the wrong thing)...

I have URLs like;

http://www.mysite.com/login.aspx?id=12
or
http://www.mysite.com/userinformation.aspx?id=12

I don't want to display the querystring part of it.

http://www.mysite.com/userinformation
0
 
käµfm³d 👽Commented:
OK, but where did the 12 go? Won't you need that to query your database or something? I would expect you to want something like:

http://www.mysite.com/user/12

...for example. You can code that into your aspx page directly (dynamically). All the links on your page are served up like the above (i.e. they are embedded into the HTML in that structure).

Now, the rewrite engine will take over once the user clicks on a link. When the server gets the request for a page, it will initially see:

http://www.mysite.com/user/12

BUT, the rewrite engine will use the rules you have set up to change that request into something that looks like this:


You users never see this particular URL. You use the former to make your users happy; you use the latter to make the server happy.
0
 
käµfm³d 👽Commented:
Sorry, I copied the previous example. The server version will be:

http://www.mysite.com/userinformation.aspx?id=12

Disregard the bit about "search.aspx". My apologies.
0
 
CamilliaAuthor Commented:
Yes, I want the user to see
http://www.mysite.com/user/12

NOThttp://www.mysite.com/userinformation.aspx?id=12

So, what am I missing on the rewrite to make the links look like that? If you look my initial post and Scott Guthrie's link, I even tried something like his example:

<rewriter>
    <rewrite url="~/products/(.+)" to="~/products.aspx?category=$1" />
  </rewriter>





0
 
käµfm³d 👽Commented:
What I am saying is you have something like this for your aspx page:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# string.Concat("http://www.mysite.com/user/", Container.DataItem("userid")) %>'>This is my hyperlink</asp:HyperLink>
</asp:Content>

Open in new window


Notice how the hyperlink creates the URL, but the URL that it creates is of this form:

http://www.mysite.com/user/12

When the user gets it, it's of that form; when the user clicks the link, that form is seen in the address bar. You created that form, and you passed that form to the user.

Now, on the server, you have a rewrite rule:

<rewriter>
    <rewrite url="~/user/(.+)" to="~/userinformation.aspx?id=$1" />
</rewriter>

Open in new window


This makes the server *think* your user clicked a link that looked like:

http://www.mysite.com/userinformation.aspx?id=12

The server rewrites the URL that the user *actually* clicked on to look like the one that the server actually expects.
0
 
CamilliaAuthor Commented:
Yes, but shouldn't  putting this in webconfig
<rewriter>
    <rewrite url="~/user/(.+)" to="~/userinformation.aspx?id=$1" />
</rewriter>

do this??
So, when user logs in, current page's URL is
http://www.mysite.com/userinformation.aspx?id=12

but i want them to see http://www.mysite.com/user/12

I get all that. I need to depoly the code to the hosting server to actually see the rewrite then?


0
 
CamilliaAuthor Commented:
ok, LOL, sorry, it's been a long day. Let me depploy to the hosting server and see how it works.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.