views:

122

answers:

3

Hi, i am working on a project that you can subscribe with your company name and you can use all features of site specificly to your company. for example company abcd can get its own url from our website like

www.test.com/abcd/productlist.aspx

company efgh can also login with its own url and see its product list.

www.test.com/efgh/productlist.aspx

can any one help me how can i implement this with my site with best approaches

I am thinking on the approach that will use Global.ascx file to distinguish companies, i will write code to extract company name from url in global.ascx for every valid request and in all the pages i will put this.form.action = request.rawurl.

is there any other approaches? if anybody implemented this type of feature, please let me know your approaches.

Thanks

A: 

Take a look at these questions.
Your approach has a name. It's called Multitenancy.

cottsak
+1  A: 

If you're working with ASP.NET 3.5 SP1 then you should investigate the new routing engine that has been introduced from the MVC project. It will make for a clean solution.

Ajw
A: 

We are using the DLL from http://urlrewriting.net and rules similar to the following:

<urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07"&gt;
  <rewrites>
    <add name="Customer" virtualUrl="^~/([^/]+)/([^/]+).aspx" destinationUrl="~/$2.aspx?customer=$1"/>
    <add name="CustomerStart" virtualUrl="^~/([^/]+)/$" destinationUrl="~/Default.aspx?customer=$1"/>
    <add name="CustomerStartAddSlash" virtualUrl="^http\://([^/]+)/([a-zA-Z0-9_-]+)$"
                                      destinationUrl="http://www.example.com/$2/"
                                      redirect="Domain" redirectMode="Permanent" />
  </rewrites>
</urlrewritingnet>

Those rules do the following mappings. These are rewrites, so the user always sees the left-hand URL in his browser:

Rule 1: http://www.example.com/customerA/something.aspx => http://www.example.com/something.aspx?customer=customerA
Rule 2: http://www.example.com/customerA/ => http://www.example.com/Default.aspx?customer=customerA

The third rule is a redirect rather than a rewrite, i.e., it ensures that the trailing slash is added in the user's browser (makes sure that relative paths work correctly):

Rule 3: http://www.example.com/customerA => http://www.example.com/customerA/
Heinzi