Asp.net 3.5 Sp1 Sub-Domain routing?

我的未来我决定 提交于 2019-12-08 09:53:07

问题


I was wondering is there is a way to introduce sub-domains in Asp.net 3.5 routing

All i found as this http://blogs.securancy.com/post/ASPNET-MVC-Subdomain-Routing.aspx

But i was looking for something more complex to allow doing wild-card sub-domains

Any Help ?


回答1:


Should be no problem, even with that sample. In this case, just add a wildcard to your DNS "*.yourdomain" and use the 'default' statement from the switch to handle wildcards.

In other words, change the sample for the Global.asax to something like:

                default: 
                returnValue = new RouteData(this, new MvcRouteHandler());
                returnValue.Values.Add("controller", "MyControllerName"); 
                returnValue.Values.Add("action", "MyActionName");

                // for example, provide the entered subdomain as parameter;
                returnValue.Values.Add("MyActionParameterName", subDomain); 
                break;

And don't forget: add a wildcard to your DNS. It shall not be possible to test subdomains on localhost, though.



来源:https://stackoverflow.com/questions/881574/asp-net-3-5-sp1-sub-domain-routing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!