Asp.Net MVC 应用程序中的子域
嘿伙计们!
我将开始开发一个营销网站,用户将能够在该网站中创建帐户。我想使用子域来分隔用户区域,就像 wordpress.com、ning.com 等。如果用户创建一个帐户,例如:“john”,则网站应在 john.mydomain.com 中对此进行响应用户区域,但它将是相同的代码(分隔我的子域)。
我想知道,如何编写代码来识别帐户(在子域中)以显示网站的正确帐户?
PS:当然显示网站是不需要认证的。
谢谢
Helo Guys!
I'll start to develop a website of marketing and the users will be able to create accounts in this website. I'd like to separete the area of users using Subdomains, just like wordpress.com, ning.com, etc. If a user create an account for example: "john", the website should respond in john.mydomain.com for this user area, but it'll be the same code (separating my subdomain).
I'd like to know, How can I do a code to identify the account (in subdomain) to show the correct account for the website ?
PS: Of course it isn't to be authenticated to show the website.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我和我的朋友得到了我们的网站之一。我们有一个数据库表,其中包含 SiteId 以及域。
在基本控制器中,我们在域进入时对其进行解析,然后在数据库中找到适当的 SiteId。所有控制器都继承自该基本控制器,并且 SiteId 被传递到对模型的每次调用。
当有人点击 Admin.Site.com 时,SiteId 1 被传递到模型以检索数据或保存/编辑/添加/删除数据。
这是我们用来获取域名的代码:
My buddy and I get this one of our sites. We had a database table that held the SiteId, along with the Domain.
In a base controller, we parsed the domain when it came in, and then found the appropriate SiteId in the database. All the controllers inherited from this base controller, and the SiteId was passed though to each call to our model.
When someone hit
Admin.Site.com
, SiteId of 1 was passed to the model to either retrieve the data, or save/edit/add/delete it.Here is the code we used to get the domain:
asp.net mvc 中的路由处理在域名之后开始,因此无法使用常规路由处理捕获它。
您可以创建一个路由处理程序,在评估路由之前将子域添加到路由数据中(从 Request.Url 获取)。
The route handling in asp.net mvc starts after the domain name so it can not be caught using regular route handling.
You can create a route handler that adds the subdomain into the route data (taking it from the Request.Url) before the route is evaluated.