I’m trying to play around with URL rewrites and can’t get it to work.
-
I have a URL,
http://localhost/CToastWebsite/Rooms.aspxand want to write it ashttp://localhost/CToastWebsite/Rooms -
And I have another URL,
http://localhost/CToastWebsite/Rooms.aspx?type=CreateRoomand want to write ithttp://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.
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.