Hide url extension - asp.net

I want to hide or modify the url extension by default it is set to aspx. Can it be modified in asp.net

You have to use URL rewriting.
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

Probably you're trying to create friendly urls. If this is the case you need to use "URL rewriting". We could give you more info if you tell us which version of the .NET framework you're using and the version of the IIS.
Here you'll find a general definition of url rewriting. Once you provide extra information about your infraestructure we can point you to the correct tool.

Related

Asp.net 2.0 Hide Default.aspx from Url

I have one issue with my site. I need to hide Default.aspx from Url. My web site project uses urlrewriter net and I tried using it to make this but no success.
I read lot of articles on net how to do this but nothings work.
Does this is only possible to set on IIS ?
I wont all ways to have www.test.com instead of www.test.com/default.aspx
Please for best solution ?
If you're using iis 7 or above, this might be a way of going about it.
The Microsoft URL Rewrite Module 2.0 for IIS 7 and above enables IIS administrators to create powerful customized rules to map request URLs to friendly URLs that are easier for users to remember and easier for search engines to find. You can use the URL Rewrite module to perform URL manipulation tasks.
http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module
And heres a link to see the module in action.
http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
After reading tons of articles this is solution for my problem..
setting this javascript onto masterpage
var testremove = location.href.toLowerCase().indexOf("default.aspx");
if (testremove != -1) {location.replace(location.href.substring(0,testremove))};

how to show dynamic html page instead of aspx page with query string variables

we are using framework 3.5 please let me know how can I achieve following
instead of showing
http://www.mydomain.com/microsite/index.aspx?projid=3&adid=5
I want to show something like
http://www.mydomain.com/[cityname]/[keyword]/[customer-project-name]/index.html
where [cityname],[keyword],[customer-project-name] will be dynamic based on projid, adid
we want to do this for SEO
Use Urlrewritting to make your pages more Url / user friendly.
Please consider reading below mentioned articles and that may be helpful to you.
http://msdn.microsoft.com/en-us/library/cc668201.aspx
How to SEO friendly an existing ASP .NET 3.5 web application under IIS6
You could create a HttpModule which rewrite the url or use a existing Url Rewriting Module like UrlRewriter.net . Here is a blog post about this subject.

How to SEO friendly an existing ASP .NET 3.5 web application under IIS6

So, I know there's a lot of this subject here and over the Internet. But most articles/questions refers to "static" url rewriting, like:
www.site.com/products.aspx?category=Books
So they rewrite it to
www.site.com/Products/Books
That's ok but I need something else.
The site is like a CMS, it has different types of content.
Nowadays to read the article titled "How StackOverflow helps you in your development" you need to go to an URL like the following.
www.site.com/viewContent.aspx?Id=1234
What I want to achive is:
www.site.com/Content/Articles/how-to-stackoverflow-helps-you-in-your-development
So as I understand, I need to involve ASP .NET in that, because first I need to retrieve the article (an its title of course) and then rewrite the URL.
But I'm wondering how the hell ASP .NET will know how to get that article if I go to that URL, it doesn't include the id anywhere...
So maybe I could accept something like
www.site.com/Content/Articles/1234/how-to-stackoverflow-helps-you-in-your-development
I'm kind of lost here really.. I've never done any URL Rewriting at all and I've googled a lot and I cannot find a way to do what I want. Maybe what I want is not called url rewriting??? I don't know...
The site is running under Windows 2003 Server, IIS6, ASP .NET 3.5 SP1
And of course, I need a free solution, cannot spend 100usd on the ISAPI mod (besides I don't know if that is going to do what I need).
Thanks to all and sorry if this is a duplicated question, but I couldn't find it.
EDIT: I don't need to support non-ASP.NET files (jpgs, gifs, etc) don't need to be rewritten. I just need to rewrite the viewContent page to include the content title into the URL.
You can use the new Routing that comes with ASP.Net 3.5 sp1 to have clean URLs.
This can even be done in web forms and not just MVC. ( I have done it myself). See here and here for exanples of how to set it up.
You can throw the Id of the article and the title in the URL and make the Id the real parameter that gets used to search for the article. That is what SO does. Try removing the question for the URL and it will take you to the same place.
Even if you don't use the Id you can pass the title of the article "how-to-stackoverflow-helps-you-in-your-development" to your DB and retreive the article based on the title.
With regards to IIS 6 it is a little trickier since IIS 6 by default can't handle extension-less URL's.
There are a few work arounds:
Use the wildcard mapping in IIS to map all requests to Asp.Net
Put Default.aspx at the end of your urls
See this post for other possible solutions.
Although the first solution may have performance issues if all content in your site goes through Asp.Net (even images, css, .html ...) in a small site it shouldn't matter. I have used this approach and there wasn't any major performance issues. I think it is the simplest solution. Here is the website I built with it
I hope this helps.
This one is free, I have used it and it works pretty well: http://www.codeplex.com/IIRF
The nice thing is that it will handle url's without an extension (i.e. .aspx, .html, etc.)
You can achieve this with ASP.NET routing.You can do this with ASP.NET MVC as well as Webforms.No need to do anything with IIS.
Check the below link
https://web.archive.org/web/20201205221404/https://www.4guysfromrolla.com/articles/051309-1.aspx#postadlink
I did URL routing in my web application within 1 hour with the details from the above link.Its quite simple to learn .They provide sample codes too.It will help you to do it easily
You can retrieve the Id of the content using the title.But title should be unique.You can use ajax to check whether the title is a already existing one when user takes mouse out from the textbox.
Easiest way is to add a http module to your current webforms project.
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
This shows you the basics of it, But it can easily be expanded so that the pages you want to rewite is taken from a database or even built on the fly.
ASP.net MVC is your friend for that
stackoverflow use MVC

How do I redirect this url pattern in asp.net webforms or asp.net mvc?

I am trying to redirect a user when they entire a URL in this format:
http://example.com/http://example2.com/
To the following:
http://example.com/?m=example2.com#http%3A%2F%2Fwww.example2.com%2F
I want to strip out the host of example2 and make it a query-string, then URL encode the full URL of example2 and put it as the anchor.
What is the best way to do this in asp.net? I can use mvc, iis7, or iis6. I know I could do this by mapping everything to .NET in IIS6 and then using httpcontext.rewritepath but I bet there is a better way.
Thank you.
Unfortunately, ASP.NET does not allow a colon anywhere in the URL path. Not even an escaped colon (%3A). It is only allowed in the querystring portion of the path.
This restriction is in place even before URL rewriting happens. (You'll get the 400 Bad Request error.) In that question, the asker answered their own question with a link to Stefan from the ASP.NET team.
Of course, you can still collect the URL from your user any way you like, and format the URL or redirect in a way that ASP.NET can use.
What do you think about urlrewritting concept of ASP.net. I think it can solve your purpose

ASP.NET URL rewriting not working with folder URLs

I wrote a custom URL rewriting module, to take certain paths and map them to our catalog out of the database.
I am using the technique outlined in the link at the bottom of my post.
I'm using .NET 3.5. The problem is that it only works when there is a page name on the end of the original URL, but if the page name is left off, then it never even calls my handler.
So for example, the URL
http://mysite.com/folder/index.aspx works but
http://mysite.com/folder/ does not.
The one with just the folder never gets into my handler class at all. Is there something you need to do to enable folders to work properly?
http://www.simple-talk.com/dotnet/asp.net/a-complete-url-rewriting-solution-for-asp.net-2.0/
Is a know issue when using .NET rewriting. You need to correctly configure the wildcard mapping. Here is a good link:
http://devtalk.dk/2007/03/19/Wildcard+Mapping+And+URL+Rewriting+On+IIS7.aspx
Another option will be rewriting by IIS ISAPI with regular expressions.
In my company we actually use both.
Check out this link for references:
http://www.kowitz.net/archive/2006/09/15/url-rewriting-using-ihttpmodule-vs-isapi-rewrite.aspx
I'm not sure how to solve it but the reason is becaus IIS is treating it as a directory (which it is) and doesn't have any knowledge about how to pass the folder to the ASP.NET isapi filter and trigger the .Net handler.
You could try doing it with IIS7 and inserting the handler in the actuall IIS pipeline. Or check the bottom of the article you referenced below the heading "Using RewriteModule".

Resources