How to efficiently create facebook-like url-rewriting in asp.net - asp.net

I'm currently looking into url-rewriting and how it should be done right and hope you have some inputs here.
At the current stage of development only the kind of url-rewriting I'm interested in is adding facebook like behavior to businesses to which we provide services on our site, i.e. www.mysite.com/ShowBusinessInfo.aspx?id=1 should be rewritten to www.mysite.com/HostedBusinessName. - The idea is that when a business registers on our site they can choose whatever the last part of the url should be.
What would be the best way to support this feature? Custom IHttpModule, Global.asax (I'm afraid that this is too slow?), UrlRewriter.net/UrlRewriting.net or a completely different solution.
The site is developed in asp.net and runs on IIS 7.5.

I've actually done something like this before and this is the article I used as a resource: http://stweet.wordpress.com/2010/03/15/creating-a-new-website-programmatically-on-iis-using-asp-net/
This article will tell you how to programmically add a web site to your IIS using C#. Keep in mind that depending on how your IIS and DNS is setup, you may need to also modify your DNS server. You can find various scripts for doing this here: http://msdn.microsoft.com/en-us/library/ms682129%28VS.85%29.aspx
Hope this helps!

If you have fairly simply rewriting rules, I'd use an IHttpModule that attempts to match the URL's LocalPath property with a value in your DB, and then calls context.RewritePath(string).
If you have more complex stuff, then I'd start looking at UrlRewriting.NET or the routing options in ASP.NET.

Related

Different domain names pointing to subfolders in Azure

Not sure if what I'm describing is possible, but if so I'd like to know how.
I have an ASP.NET Azure Shared mode website with a domain, lets say mydomain.com pointing to it. I have a shop there, which is currently at mydomain.com/shop.
What I'd like is to point a different domain, myshop.com to the page at mydomain.com/shop. Can I do that?
Probably the quickest approach would be URL-Rewriting, which is installed by default on Azure Website / WebRole.
Configuration can be made in the web.config -> more details although you I would imagine if you're using MVC there might a slightly more elegant Routing method, maybe?
I'm not sure if I get your question right, but
you could use the HttpResponse Redirect from the .net framework in order to redirect the response.

URL handling in ASP.NET WebForms

What's the best approach to provide URL handling in an ASP.NET application to produce results similar to Craigslist. Specifically, I'm looking to handle something like "newyork.mysite.com" and "california.mysite.com", along with parameters such as "newyork.mysite.com/products/hardware". Based on the "location" (newyork.), my goal is to change the site's look and feel and filter it's data results -- standard stuff I would think.
At the moment, ASP.NET MVC is not an option for the site (from what I've read, this sort of functionality is something that MVC excels at), but I can use .NET 4.0. Also, I was wondering what roles DNS would play in this scenario. Is the subdomain just a wildcard or are there any special considerations I would need to make?
The majority of my web development experience has been internal, intranet applications, so URL handling like this is not something I've ever really needed to do. I'd appreciate any advice (best practices, pitfalls, etc) as to how to approach this.
You can avail of the ASP.NET 4.0 routing engine to create friendly URLs:
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
You can create URLs like:
california.mysite.com/home
california.mysite.com/about
california.mysite.com/products
As regards "california.mysite.com", the "california" part represents a sub-domain. This is set up by adding an A record in your host admin and setting up IIS 7 to recognize it.

Help in locating the URL rewrites in place for an asp.net website

First off i'll advise i'm not familiar with implementing url re writing on any level.
That said I do know there are 2 types or rewrites setup for this site.
One I can locate and is solely responsible for top level rewrites (turning .com to .co.uk)
There is another rewriter implemented somehow somewhere, very early on in a pages lifecycle and I cannot find how or where the site is doing this. It's possible it's all handled in a 3rd party DLL but I would like to know the steps I might go through to prove or disprove this.
Thanks
What does your web.config have registered in the httpModules section? Often URL Rewriters are registered very early in the request life cycle. httpModules and httpHandlers can grab the request here. This is of course assuming you've ruled out IIS redirects. After that you can look for manual redirection in the global.asax file. There are a lot of places to look when you don't know how the original coder decided to implement the idea. I've seen some bad places, including in the constructor of a common base page inherited by every page on the site.
URL rewriters are typically ISAPI filters - you can search currently applicable ISAPI filters on Web Site or Folder properties in IIS 6 (you might have ISAPI filters in right context menu), on II7, ISAPI filters in features view when you select web site or folder.
With .NET 3.5 or 4.0, its possible that ASP.NET routing might be the reason - you can locate that in web.config or global.asax (common places for putting the routes).
My word i'm so sorry after finally tracking down an original dev there is no re-writes whatsoever. The solution is complex but workable. Weird etc :). Love IT.

Display web page from another site in asp page

Our customer has a requirement to extend the functionality of their existing large government project. It is an ASP.NET 3.5 (recently upgraded from 2.0) project.
The existing solution is quite a behemoth that is almost unmaintainable so they have decided that they want to provide the new functionality by hosting it on another website that is shown within the existing website.
As to how this is best to be done I'm not quite sure right now and if there is any security issues preventing it or that need to be considered.
Essentially the user would log on to the existing web site as normal and when cliicking on a certain link the page would load as normal with some kind of frame or control that has within it the contents of the page from the other site. IE. They do not want to simply redirect to the other site they want to show it embedded within the current one such that the existing menus etc are still available.
I believe if information needed to be passed to the embedded page it would be done using query strings as I'm not sure if there is even another way to accomplish this.
Can anyone give me some pointers on where to start at looking to implement this or any potential pitfalls I should be aware of.
Thanks
if the 2 sites are hosted from the same network (low latency between them) you could use state server for session management. that way, when you authenticate on one site, you will also be authenticated on the other, and share user state across them.
its pretty simple, in your web config of each web server you'd point to the state server (which could be located on one of the web servers)
<configuration>
<system.web>
<sessionState mode="StateServer"
stateConnectionString="192.168.1.103:42424"
/>
</system.web>
</configuration>
http://en.csharp-online.net/ASP.NET_State_Management%E2%80%94Storing_Session_State_out_of_Process
create a virtual directory under the primary domain. If your domain is www.mydomain.com then create a virtual directory www.mydomain.com/site and port the new website application under /site virtual directory. This was linking should become very much relavant. With this the virtual-directory application will also retain all domain cookies set by primary domain.
I would suggest to make the second website look exactly like the first one or at least use the same MasterPage, so you can redirect from one site to another without any visual difference.
If your site needs authentication, consider that you would need to do something to prevent the user to log in twice, an option could be to send an encrypted token to the second site.
All of this if you are forced to have a second site, if not just use a virtual directory
You could use something like UFrame. I've used it a couple of times and seems to do quite a good job with it...
"goodness of UpdatePanel and IFRAME combined"
http://www.codeproject.com/KB/aspnet/uframe.aspx
I would use an iFrame to embed that website in within your existing application. Just set the "src" attribute and pass in any query string parameters the other site needs to render correctly.
You can still pass in sensitive data in the query string, however it would make sure to encrypt it before sending it in.
I know it is not the most elegant solution, but it gets the job done. And from the description of the existing app, it doesn't seem like your customer cares for "elegance" :)
Hope this helps

Using hosting companies "404 error behavior" to implement URL Routing

Many hosting companies let you define which page will be shown to the user if the user goes to a page that does not exist. If you define some .aspx page then it will execute and be shown.
My question is, why not use this for routing. since I can parse the users URL and then do a server.transfer to the page I want. I checked and there is no redirect sent to the client and the http headers are HTTP/1.1 200 OK.
So, is this a good idea for servers that don't have ASP.NET 3.5 SP1 or if you are not using MVC?
Thanks
You "can" do that, but why not just create an HttpModule and handle the routing there? That's how most of the URL rewriting systems work (in actuality, it's also how the MVC routing works since global.asax is just a pre-build HttpModule with a few extras).
The big thing with relying on that kind of server handling you describe is that you really aren't in control of it, and it is a hackish mechanism... by that I mean you are taking a function of the web server that has a specific purpose and design and laying a different meaning and function on top of it... which means you now have no built in handling for an actual 404 error. Plus, the mechanism you are contemplating is harder to adapt to your purpose than just using the other options available to you.
Unless you need something special from routing, you should consider using an existing routing component such as Mod-Rewrite or one of the dozen or so other popular URL rewriters that were built before the MVC routing engine was implemented and work fine in older versions of asp.net. There are also numerous tutorials on using HttpModules, HttpHandlers, and various other techniques to do routing in asp.net webform environments.

Resources