-1

I'm trying to play around with URL rewrites and can't get it to work.

  1. I have a URL, http://localhost/CToastWebsite/Rooms.aspx and want to write it as http://localhost/CToastWebsite/Rooms

  2. And I have another URL, http://localhost/CToastWebsite/Rooms.aspx?type=CreateRoom and want to write it http://localhost/CToastWebsite/Rooms/CreateRoom.

How would I go about doing this?

I have tried and my CSS and images do not work even though I use /styles/styles.css with URL http://localhost/CToastWebsite/Rooms.aspx/CreateRooms. Is this the correct way of using a URL like this?

I'm stuck, and I have searched for articles, but I can't find anything that is easy to follow and get the CSS and images to work.

EDIT

I have set up urlrewritingnet.net, but I am having problems. I set a rule such as:

<urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07" >
<rewrites>

  <add name="Rewrite"  virtualUrl="^~/Rooms"
       rewriteUrlParameter="ExcludeFromClientQueryString"
       destinationUrl="~/Rooms.aspx"
       ignoreCase="true" />

</rewrites>

</urlrewritingnet>

So I want /rooms.aspx to change to /rooms, but the page keeps displaying /rooms.aspx.

Session state error now

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the \\ section in the application configuration.

I have added the tag in the web.config file in <system.web>:

<sessionState mode="InProc" timeout="20" cookieless="UseCookies" />

and I have set EnableSessionState="true" in the page directive.

Solution

I followed Stack Overflow question Error using session in IIS 7 to make the session state work again.

Community
  • 1
  • 1
redoc01
  • 2,107
  • 5
  • 32
  • 64
  • Have to be honest; I use this: http://www.urlrewriting.net/149/en/home.html - it's free and it works. Personally, I wouldn't have the file extension in my rewritten URL. There are also plenty of examples on SO. You can also use something like http://www.blunck.info/iehttpheaders.html to see where your requests are going in IE, and there are plenty of similar toolbars for other browsers. – dash Dec 11 '11 at 10:00
  • You also need to configure the extension the http modules section - have you done this? See page 8 of the guide. Also, it doesn't automatically redirect; instead, you change your URL to be http://www.mysite.com/rooms, and the URL Rewriter maps that onto Rooms.aspx so no one ever sees the page itself. – dash Dec 11 '11 at 11:35
  • Also note that, depending on how you are hosting your site in IIS, /styles/ will be from the root and not from the virtual directory (i.e. you probably want /CToastWebsite/Styles/style.css). I much prefer using the themes folder for this as .Net will work out it's location. You have to be careful with your paths for images etc though. – dash Dec 11 '11 at 11:49
  • @dash im getting another error now, i have done what you said and now im getting session state errors, i have edited once again the question – redoc01 Dec 11 '11 at 13:12
  • Good work! Upvoted your question too for adding the edits. That should balance out whomever downvoted you. – dash Dec 11 '11 at 13:32
  • @dash, help once more, the styles and images are working fine its just the javascript files that are not working now – redoc01 Dec 11 '11 at 13:47
  • How are you linking to them? For now, try the absolute path /CToastWebsite/scriptfolder/scriptfile.js – dash Dec 11 '11 at 13:50

1 Answers1

-1

I personally wouldn't use a URL that had the entire page name, plus extension in it - although this makes the problem quite easy to solve (as I assume you are still requesting the original page), it, in my opinion, defeats the point of URL rewriting.

There are plenty of URL rewriting implementations for .NET that are quite easy to configure and use.

I use URL Rewriting.Net

You can use a tool to see where your requests are going. A popular one for Internet Explorer is IE HTTP Headers - this is often useful for seeing where the browser is being redirected too. This should help you determine where the requests are going for your CSS and images.

Scott Hanselman also has a post about how to do this in IIS 7.

There are also plenty of examples on Stack Overflow - look at the Related links in the bottom right hand corner for examples.

You might also want to post some example of code of how are doing your rewrites at the moment if you want to work out what is going wrong.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dash
  • 89,546
  • 4
  • 51
  • 71
  • thanks for replying, i set up the utlrewritenet but i am having problems. i have edited the question – redoc01 Dec 11 '11 at 10:56