使用子域来识别客户端
我正在构建一个 Silverlight 应用程序,而我们希望能够让客户端点击如下 URL:
http://{client}.domain.com/
并登录,其中 {client} 部分是他们的公司名称。 例如,谷歌的将是:
我想知道的是是否有人能够在 silverlight 中使用此子域模型来对 Web 服务器的调用做出决策,以便您可以切换到特定数据库来运行查询? 不幸的是,这对于该项目来说是非常必要的,因为我们正在努力让他们的员工轻松获取我们软件的公司特定信息。
I'm working on building a Silverlight application whereas we want to be able to have a client hit a url like:
http://{client}.domain.com/
and login, where the {client} part is their business name. so for example, google's would be:
What I was wondering was if anyone has been able, in silverlight, to be able to use this subdomain model to make decisions on the call to the web server so that you can switch to a specific database to run a query? Unfortunately, it's something that is quite necessary for the project, as we are trying to make it easy for their employees to get their company specific information for our software.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
将服务放在特定的子域本身(例如 wcf.example.com)上,然后在服务上设置跨域策略文件以允许其访问它不是可行吗?
只要这可行,您就可以将 silverlight 加载到正确的子域中,然后将该子域传递给您的服务并让它完成它的工作。
下面是一些示例:
Wouldn't it work to put the service on a specific subdomain itself, such as wcf.example.com, and then setup a cross domain policy file on the service to allow it to access it?
As long as this would work you could just load the silverlight in the proper subdomain and then pass that subdomain to your service and let it do its thing.
Some examples of this below:
在服务器端,您可以检查 HTTP 1.1 主机标头以了解用户如何访问您的服务器,并基于此进行必要的自定义。
On the server side you can check the HTTP 1.1 Host header to see how the user came to your server and do the necessary customization based on that.
我认为你不能单独使用 Silverlight 来做到这一点,我知道你不能在没有 Javascript、Ajax 等问题的情况下做到这一点。 这是因为出于安全原因,浏览器对子域的处理方式与子页面不同。
下面的想法怎么样:将重写规则插入到您的 Web 服务器软件中。 因此,如果调用 http://google.domain.com,网络服务器本身会将 URL 重写为类似的内容http://www.domain.com/google/(或更好:http://www.domain.com/customers/google/)。 那会有帮助吗?
I think you cannot do this with Silverlight alone, I know you cannot do this without problems with Javascript, Ajax etc. . That is because a sub domain is - for security reasons - treated otherwise than a sub-page by the browsers.
What about the following idea: Insert a rewrite rule to your web server software. So if http://google.domain.com is called, the web server itself rewrites the URL to something like http://www.domain.com/google/ (or better: http://www.domain.com/customers/google/). Would that help?
Georgi:
如果它是静态的,那就会有帮助,但可惜的是,这一切都将是动态的。 我的希望是对该应用程序进行 1 次部署,并使用 http://google.domain.com/ 想法为用户切换到正确的数据库。 我记得在我们构建一个 asp.net 网站时曾这样做过,使用域上下文来确定要使用的皮肤等。
Ates:您能详细解释一下您所说的内容吗...听起来您与我所说的很接近我正在想办法。 你见过这样的教程吗?
我想出的实现这项工作的唯一另一种方法是拥有一个元数据库,当用户登录时,它将根据需要将它们切换到适当的数据库......只是想告诉客户端 x 点击:
http://ClientX.domain.com/ 比说点击 http://www.domain.com/ 并登录。 似乎他们要点击自己的名字,并且直接从登录屏幕上为他们显示个性化的名字,这对客户群来说更具吸引力。
Georgi:
That would help if it would be static, but alas, it's going to all be dynamic. My hope was to have 1x deployment for the application, and to use the http://google.domain.com/ idea to switch to the correct database for the user. I recall doing this once when we built an asp.net website, using the domain context to figure out what skin to use, etc.
Ates: Can you explain more about what you are saying... sounds like you are close to what I am trying to come up with. Have you seen such a tutorial for this?
The only other way I have come up with to make this work is to have a metabase that when the user logs in, it will switch them to the appropriate database as required... was just thinking as well that telling Client x to hit:
http://ClientX.domain.com/ would have been sweeter than saying to hit http://www.domain.com/ and login. It seemed as if they were to hit their name, and to show it personalized for them right from the login screen would have been much more appealing for the client base.
@Richard B:不,我想不出我以前见过的任何这样的教程。 我会尝试说得更详细。
更详细的服务器端方法:
Host
HTTP 标头(例如某些平台中的“HTTP_HOST”服务器变量)。 这将包含客户端用于访问您的服务器的确切 subdomain.example.com 。 提取子域部分并继续...还可以有仅客户端的方法。 我对 Silverlight 了解不多,但我假设您应该能够使用 JavaScript 连接 Silverlight。 您可以使用 JavaScript 读取
document.location
并将其传递给您的 Silverlight 小程序,进一步的数据获取等逻辑将依赖于 JavaScript 传入的子域。@Richard B: No, I can't think of any such tutorial that I've seen before. I'll try to be more verbose.
The server-side approach in more detail:
Host
HTTP header (e.g. the "HTTP_HOST" server variable in some platforms). That would contain the exact subdomain.example.com that the client used for reaching your server. Extract the subdomain part and continue...There can also be a client-side-only approach. I don't know much about Silverlight but I'm assuming that you should be able to interface Silverlight with JavaScript. You could read
document.location
with JavaScript and pass it to your Silverlight applet, whereon further data fetching etc. logic would rely on the subdomain that was passed in by JavaScript.@Ates:
这就是我们在编写 ASP.Net 系统时所做的...我们将大量 *.example.com 主机推送到 Web 服务器,并使用 HTTP 标头进行处理。 当处理 WCF 在客户端和服务器之间推送信息时,就会出现阻塞……它只能存在于一个域中……
因此,例如,当您有 {client}.example.com 和 {sandbox} 时.example.com,WCF 服务无法注册到两者。 它也不能只注册到 *.example.com 或 example.com,所以这就是第 22 条规则出现的地方。 其他一切我都有处理的先验知识。
我记得应用程序可以在某些情况下“欺骗”另一个域名的方法。 我想在这种情况下,我需要做这样的配置吗? 我相信还有很多需要研究的地方。
@Ates:
That is what we did when we wrote the ASP.Net system... we pushed a slew of *.example.com hosts against the web server, and handled using the HTTP headers. The hold-up comes when dealing with WCF pushing the info between the client and the server... it can only exist in one domain...
So, for example, when you have {client}.example.com and {sandbox}.example.com, the WCF service can't be registered to both. It also cannot be registered to just *.example.com or example.com, so that's where the catch 22 is coming in at. everything else I have the prior knowledge of handling.
I recall a method by which an application can "spoof" another domain name in certain instances. I take it in this case, I would need to do such a configuration? Much to research yet I believe.