문제

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

도움이 되었습니까?

해결책 4

I did not found any solution that fully suites my requirement , I have written my own logic for this , which uses Global.ascx's BeginRequest, Login page, Base page and common classes created for Response.Redirect. I am no longer directly using Asp.Net's Response.Redirect, Paths and Session variables, instead I have created wrappers over them to add companyName from url to the Paths.

Let me know if you need more information on my code

Other answers are welcome.

Thanks

다른 팁

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.

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">
  <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/

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top