c# - How can I re-route a specific subdomain request to a different ASP.NET MVC controller? -


i have asp.net mvc 4 web app. has default home page handles requests http://www.mydomain.com http://mydomain.com. have mvc area set can accessed via www.mydomain.com/foo/hello/ (where "foo" name of area , "hello" controller in area).

if makes request foo.mydomain.com right now, route them default home page controller. requests foo subdomain root (eg. without specific area/controller specified) automatically rerouted /foo/hello/ controller.

additionally, want requests "foo" area via www subdomain redirected "foo" subdomain. ie. want requests www.mydomain.com/foo/goodbye automatically redirected foo.mydomain.com/foo/goodbye

i have, of course, looked @ lots , lots of other samples/questions, none of them seem address exact issue.

i'm not sure if should solve issue routes, route constraints, route handlers, etc.

additionally: application hosted on windows azure cloud services, don't have full control on iis settings.

in web server, application pool of site must have integrated pipeline mode highlighted below..

enter image description here

or can find through basic settings of application pool below..

enter image description here

then added httpmodule in sample mvc application

httpmodule

public class mymodule1 : ihttpmodule {     public void init(httpapplication context)     {         context.beginrequest += context_beginrequest;     }      public void dispose() { }      void context_beginrequest(object sender, eventargs e)     {         if (!system.web.httpcontext                        .current                        .request                        .url                        .authority                        .contains("foo.mydomain.com"))         {             string url =                  (system.web.httpcontext.current.request.url.scheme + "://" +                 "foo.mydomain.com" +                  httpcontext.current.request.url.absolutepath +                  httpcontext.current.request.url.query);             system.web.httpcontext.current.response.clear();             system.web.httpcontext.current.response.statuscode = 301;             system.web.httpcontext.current.response.status                                                      = "301 moved permanently";             system.web.httpcontext.current.response.redirectlocation = url;             system.web.httpcontext.current.response.end();         }     } } 

then added code n web.config httpmodule

<system.webserver>   <validation validateintegratedmodeconfiguration="false" />   <modules>     <add name="mymodule1" type="rewrite.mymodule1" />   </modules>   <handlers>     <remove name="urlroutinghandler" />   </handlers> </system.webserver>   <system.web>     <httpmodules>       <add name="mymodule1" type="rewrite.mymodule1" />     </httpmodules> </system.web> 

then in host file added following code.

127.0.0.1  foo.mydomain.com 

then added bindings website

enter image description here


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -