|
 |
|
|
Why not use the open source project UrlRewriter.Net (see http://urlrewriter.net). We used it very successfully at the company I worked at previously even though the site tanked big time. (Google Capazoo if you want to read about drama, controversy and laughs)
Later, Nick
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Just wondering why the second Context.Rewrite is necesary in the Page_Load? You mention it's for Postback, but how does it differ from the first rewrite;
Context.RewritePath("~/ShowContents.aspx?ContentID=11"); // in global.asax .. Context.RewritePath("ShowContents.aspx"); // in ShowContents.aspx
Both calls are on Context object - is this a double up?
"For fifty bucks I'd put my face in their soup and blow." - George Costanza
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Do I need to do anything in IIS to put this working?
I'm always served with a 404 error page from IIS!
Thanks in advance, Adalberto
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I am contemplating using this on my site, has anyone used this and if so could you please provide some feed back and any issues you may have had. Would it be better to use this or the URL rewriter solution. My site is running in a web farm.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Nice article I face one problem while rewrite url when i rewrite url css and image is not apply on my page i also write step1 line on page load of my main page but it's not working can u please give my some solution i am working on .net 2005 so on my local server how to configure iis.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi thanks for the post.
I have been working on this for a few hours and was pleased to see someone else was working toward a solution. The key for me is getting all the other resources (css, js, images, etc.) to map with those resources having relative paths.
I made a small vs project using your files and got your code to work fine. The only problem (and it's a big one of course) is that it doesn't look like other resources like css files and image files will work if they have relative paths.
For example when I added an image to both the Default.aspx file in your sample and also the same image (with the same path) to the ShowContents.aspx file, the image link is broken in the ShowContents.aspx file when it is requested via the rewritten url.
I'm sure I'm missing something. Any help will be appreciated!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
1) If you start your image path with a forward slash like this "/images/abc.gif" it will work from root directory.
2) To use relative path you should also have configured your IIS to serve all requests from ASPNET.dll. and
3) You must have
System.IO.Context.RewritePath(Path.GetFileName(Request.RawUrl));
above line in the Page_Load() event of your main page.
If above does not help, please post your code here or email me.
Thanks for visiting this and leaving a comment.
Thanks
Manu Agrawal
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi GOD Bless you I have this in my dreams ASP.NET SEF URL is Very Easier Than PHP & Apache Never Forget you for this Article Thanks a Lot! Majid
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
Hi, Did you use the code in Step 1 above? Please try step 1 and then let me know if you still get problems.
Thanks.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
well , i didn't do that before , now i did STEP 1 , but it still not working well .... i just want ot point out that im using masterPages , but i guess it does not matter
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
i have to end the request url with .aspx or .html ... etc ??
i saw some urls that look like that : www.abc.com/abc (not like www.abc.com/abc.aspx)
but it seems that global. don't get the request if it looks like this : "www.abc.com/abc " .
any idea ???
about the css problem , i just use the full path (http://www ....) not like ~/css/general.css ....
Thanks .
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Till IIS 6, only asp.net requests (e.g. .aspx, .ashs, .ascx etc.) reach to global.asax file.
If you have permissions then, you can set IIS to handle .htm, .gif etc. requests by the process that handles asp.net.
1) Open IIS admin and right click on the website you want 2) select Properties > Home Directory > Configurations 3) select the .aspx from the list, click on Edit, and then copy the process path. 4) Cancel 5) click Add then paste this path in to the top box 6) type .htm in the extension box, uncheck Verify File exists 7) Click OK
Repeat this process for any other file extensions you want like .doc, .ppt etc.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
You should check out also DotNetNuke's friendly url implementation as it provides nice framework for such functionality. One feature that I personally like is the fact that you can create a friendly url with custom parameters like "/Home/MyPage/para1/50/para2/hello" so that the "para1" maps with value of "50" and "para2" maps with value "hello" and they are accessible through normal Request.QueryString -object.
|
| Sign In·View Thread·PermaLink | 1.14/5 (3 votes) |
|
|
|
 |
|
|
What if let's say you have a GridView with paging enabled and more than a page of rows in the GridView. In a "fake URL" page.
Now you will push on the "2"-nd page link on the GridView pager. Things will get a bit nasty then.. The Request will hold a different URL like "http://machine/fakeDir1/fakeDir2/ShowContents.aspx?querystring..."
I simply can't make it look nice (it works but after the first postback the URL in the browser looks ugly) after the first postback
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Watch out if you have a validator in any of your pages because they will request a javascript throught the WebResource.axd and if in "Application_BeginRequest" you treat this as a fake URL the page will not get its javascript but whatever you serve it..
Take care as this took me 1/2 hour to figure out ..
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
For now I just put the following line in Application_BeginRequest event handler:
if (File.Exists(Request.PhysicalPath) || Directory.Exists(Request.PhysicalPath) || Request.AppRelativeCurrentExecutionFilePath.ToLower().EndsWith(".axd")) { return; }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hello, great post ...
I do not know if possible, use this technique for virtual domains like as http://virtual.domain.com
Can you help me ?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Yes, you should be able to use this with subdomains like http://virtual.domain.com without any problem. Same code will work for you.
Thanks for your feedback.
Manu
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
To all you guys using various string functions (IndexOf, Split, etc) to find your query strings and Url parts, stop! Just use a System.Uri and your done! It already parses everything for you. You may have to split the Query Strings, but at least it does the heavy lifting for you.
Thanks.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Isn't the "Custom HttpHandler" the correct (best practice) way of doing this? What advantages are in your method? Did you try HttpHandler and not get it to work? (Cuz that's what I did)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Jasmine, Thanks for your response.
An HttpHandler will take more system resources as it will listen to more requests, while only .aspx requests will be handled by global.asax file.
Please let us know if you have additional information.
Your feedback is appreciated.
Manu Agrawal
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
That is a very good point - anything that doesn't have to go through that ASP engine, is a Good Thing. In your case, adding an HttpHandler is simply overkill - all the things you want to alter are already going through the ASP engine. Mine actually responds to all requests that aren't aspx pages, and now that I think of it, that's why I didn't use something similar to your method in the first place. I had a slightly different requirement than your site. In my case, I wanted to handle all files with my custom handler, so I had to re-map the file type *.* to be handled by the ASP engine. This means all requests to my site are going through the ASP engine. That's a clear performance problem, but it adds the ability for me write custom file handling code very easily. Your method is better, if the files you are handling are aspx files, but what would you do if you needed to serve up music, video, and various application-specific documents (like .doc, .ppt, etc)?
The reason I ask is because it took me a long time to get the HttpHandler to work correctly, and nobody out there was able to help me. I finally figured it out myself, but I was amazed at the sheer number of people who basically said to do it another way. Your method seems to be a popular alternative, and one that most people seem to use when they find out that HttpHandlers are tricky to get right.
(I'm basically building a compliance system... such that users from different companies can only get the documents that are approved by their compliance department. There is a possibility of us having multiple versions of the same document, one for each company, but we want the URLs to be the same so people can share them between companies, and everyone still sees the correct versions. We want the server to serve up the correct version based on the user's login, and we wanted to send back an error if the person is not logged in, or if the company does not have an approved version of the requested document. This had to work with all requests for the document, regardless of the actual URL used.)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |