I am working on a social networking site. A user has an own profile-page.
A profile-page link example:
www.example.com/Profile.aspx?Username=Mike
Is there a way to remove the Profile.aspx from the link? (the Profile.aspx references to a Profile.cs)
And is there an other way to remove ?Username= ?
I just would like to have a simple and clear link like: www.example.com/Mike
Thanks in advance!
There are two possible method you could use:
If you are on .NET 4.0 or higher you can use routing (as already mentioned by #Arsen.
Another way would be to use URL rewriting. With URL rewriting you can tell IIS to process each incoming URL and map it to a different URL. More information on URL rewriting can be found here: http://www.iis.net/downloads/microsoft/url-rewrite
Related
I have a subdomain that is http://trade.businessbazaar.in . I am dynamically creating urls from database something in this manner http://trade.businessbazaar.in/mycompany. To display details, I have an index.aspx file there,thinking that on every request the index.aspx page will load and display data accodingly. Also, There is a masterpage on the index.aspx page from where i am capturing the text mycompany and query it in database to fetch result. But nothing seems to work.
A genuine link is http://trade.businessbazaar.in/Symparlife. But its unable to load index.aspx. I need a clean approach without any third party dll or rewriters. Directly to push some lines in config and start working. That is url will be the same but index page will get loaded...
In short, i want to say
I need the StackOverflow type clean url mechanism to fetch pages
Thanks in Advance
You can handle the Begin_Request event in Global.asax and add custom code to redirect to index.aspx and convert the parts of the URL into query string arguments. You should use Server.Transfer to keep the URL in the browser.
I'd recommend upgrading to 4.0 and using the Routing enine though. You should check if the standard routing is available as a download for ASP.NET 3.5. I am sure your code will get messy very soon. Been there, done that.
As #Mike Miller mentions in the comments the Routing engine ships with ASP.NET 3.5. You can check the documentation here - http://msdn.microsoft.com/en-us/library/system.web.routing(v=vs.90).aspx
Here is a tutorial on how to use it with Web Forms - http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx
For your case the code would be something like:
routes.MapPageRoute("company-index", "/{company}", "~/index.aspx")
And in index.aspx you can access the route value for company like this:
string company = (string)Page.RouteData.Values["company"];
Keep in mind that you'd better add something in the URL before your actual argument (the company name). If you don't you will have problems later on when because you may want to add a URL like "/Login" but then you will have to validate that users can't create a company named "Login". Not how Stack Overflow has "/questions/" before the actual question info in the URL.
I would like to shorten a url (e.g. http://www.abc.com/products/bag.aspx) to something like (http://short.me/bag). I have found that rules can be added to web.config to detect the short link to open the correct page. But I need a dynamic web.config. Is it a good idea to keep updating the web.config whenever a user creates the short url? Or is there a better way to do it?
I have tried YOURLS, RewriteRule, etc. All don't seems to work properly on my server. I am using a WIN server. I don't really want to use the bitly API as I would like to have my own domain in front of the link. Or is there a way to use the bitly API and still retaining my domain name?
Thank you.
You need to create a database mapping short URLs to long URLs.
You would then create an HTTP handler that looks up the short URL in that database and redirects to the corresponding long URL.
Then, register that handler to run for all requests.
Bit.ly lets you use custom domain names now: https://bitly.com/pro/products, check out this part of their FAQ
I'm using an action filter that checks what browser version is being used on my site, if it's an older browser I put up a div at the top asking them to upgrade. I don't want web crawlers to get the div message, so I've implemented HttpBrowserCapabilitiesBase.Crawler and it looks like it works for Google, but Bing and the others don't seem to register as crawlers. Strange for a Microsoft product to not notice Bing as a crawler!
Is there some way to add user agents to the crawler property or something?
Thanks!
Edited: I'm using asp.net mvc 3, it looks like I need to user .Browser files(?). Anyone know of a comprehensive set of .Browser files out there for Bing and the rest of the crawlers?
You will probably need to update your browscap.ini file as the one shipped with IIS is probably old. You can get a new one at one of the following URLs:
http://browsers.garykeith.com/downloads.asp
http://owenbrady.net/browsercaps/
browscap.ini usually lives at: c:\windows\system32\inetsrv\browscap.ini
We're not using MVC but we do this:
Regex.IsMatch(Request.UserAgent, #"bot|crawler|baiduspider|80legs|ia_archiver|voyager|curl|wget|yahoo! slurp|mediapartners-google", RegexOptions.IgnoreCase);
More options in my answer here:
Detecting honest web crawlers
I am developing an application in SharePoint 2010.
What now I have to resolve is the following:
I have a list of news. Each one has an ID and Title.
I have one SharePoint page that knows how to display them.
I need that instead of linking each news as:
http://sharepoint/news/viewnews.aspx?title=MySharePointNews01
Be as the following:
http://sharepoint/news/MySharePointNews01
I think tha writing an HttpModule and doing Server.Transfer to the Viewnews.aspx will accomplish this.
Any recommendations?
Thanks in advance.
Have a look at the IIS URL Rewrite module. It will do exactly what you are looking for without having to write any code. This article explains it pretty clear:
http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module/
You can download IIS URL Rewrite here: http://www.iis.net/download/urlrewrite
A client has sent out an email with a link containging a typo for a website we run [E.g. http://example.com/?id=123.]. What is the best way to re-direct anyone who visits the bad URL?
If someone clicks on the link, can we catch it in the Global.asax, checking if the path ends with "." then removing it and re-directing? If so, where in Global should it be?
If another method is better I'm happy to hear it; the most important thing is speed as this is needs to be nipped in the bud ASAP!
Its not the best solution, but you could use Application_BeginRequest in the global.asax file.
And better way if you are using IIS 7.0 is URL Rewriting
You need to use something like ISAPI_REWRITE for url re-writing in IIS (If IIS 6) because I'm not sure that that request would even be handled by .NET with that extension
If you happen to not have IIS 7.0 you can always use ISAPI_Rewrite (the free edition). Working mainly on regex you can redirect or rewrite any url.
http://www.helicontech.com/isapi_rewrite/