简体   繁体   English

如何使用C#和asp.net创建带有用户名的子域?

[英]How to create subdomain with username using C# and asp.net?

When a user registers with my site, they will get a url like this " http://username.mysite.com " to access their page/folder. 当用户向我的网站注册时,他们将获得一个像这样的“ http://username.mysite.com ”网址来访问他们的网页/文件夹。 How this is possible using C# and asp.net mvc. 如何使用C#和asp.net mvc实现这一点。

Any help is appreciated. 任何帮助表示赞赏。

Rather than have the username as a subdomain how about having it as part of the URL path. 而不是将用户名作为子域名如何将其作为URL路径的一部分。 Would be a lot easier for you to implement. 实施起来会容易得多。

www.mysite.com/users/ravi
www.mysite.com/ravi

Then you could tailor your View page dependent on the username. 然后,您可以根据用户名定制View页面。

I was also looking to implementing your scenario and have some links bookmarked. 我还希望实现您的方案并将一些链接加入书签。 Maybe this will get you on your way until some SO superstar gives another complete sample ;) 也许这会让你继续前行,直到一些超级巨星给出另一个完整的样本;)

http://blogs.securancy.com/post/ASPNET-MVC-Subdomain-Routing.aspx (link down) http://blogs.securancy.com/post/ASPNET-MVC-Subdomain-Routing.aspx (链接下)

  • Step 1: Custom RouteBase 第1步:自定义RouteBase
  • Step 2: Create the Controller 第2步:创建控制器
  • Step 3: Register the Routes 第3步:注册路由
  • Step 4: Subdomains on localhost IIS 第4步:localhost IIS上的子域

At the end of the article, it also references another SO post: 在文章的最后,它还引用了另一个SO帖子:

Is it possible to make an ASP.NET MVC route based on a subdomain? 是否可以基于子域创建ASP.NET MVC路由?

It seems like a SO superstar has already answered the question :) 似乎SO超级明星已经回答了问题:)

您可能希望在MSDN上查看IIS API

I'd agree with @David (+1). 我同意@David(+1)。 Not only would it be easier to implement but it would be much more consistant for your site in regards to analytics, stats and probably most importantly, caching ! 它不仅更容易实现,而且对于您的网站而言,它在分析,统计数据以及最重要的缓存方面可能会更加一致! There's probably several other reasons too! 可能还有其他几个原因!

Unless you want to treat each user as a client, which is different. 除非您希望将每个用户视为客户端,否则这是不同的。 But if they are all in the same domain then I'd advise to go with @David's suggestion. 但如果他们都在同一个领域,那么我建议按照@David的建议去做。

你也可以用自定义的HttpModule制造假子域的说明这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM