domain specific ASP.NET MVC5 route with IIS rewrite - asp.net-mvc

I have an MVC5 web application which maps to a domain www.example.com. I'm using basic {area}/{controller}/{action} based routing in my webapp and would need to map a subdomain to a specific route.
For example:
subdomain.example.com needs to always server content from http://example.com/area/controller/action
Ofcourse the route has to work with ASP.NET MVC5 routing and also all query parameters and "hashbang" data need to be retained so that:
http://subdomain.example.com#/somethinghere?var=value redirects content from http://example.com/area/controller/action#/somethinghere?var=value
So the question is: is this achievable with IIS routing/rewriting and if so, how? Another option would be to write custom MVC5 route which binds to a domain and I would love to see someone point me to a right direction with that, too.

This will not be possible, anything after the hash is client side only and the browser will not send it back to the server. As it is not send to the server there is no way to rewrite it.
As an alternative you can consider changing your routing to use pushstate instead of hashstate

Related

IIS URL Rewrite based on logged in user

I have a scenario whereby I want to route http requests from authenticated users to specific websites hidden behind a reverse proxy. The decision of which site to route too is based on the specific user. For example, user 'Mary' may be routed to site "b"; user 'John' may be routed to site "e".
I am hosting the sites on IIS and am using ARR as my reverse proxy. I'm trying to figure out the best way to use URL Rewrite to make the routing decision.
One idea I had was to build a custom URL Rewrite provider that decrypts the FormsAuthTicket (created by an ASP.NET MVC website) and makes the routing decision based on information in that cookie.
Can anyone provide some guidance on how I can solve this problem? Am I on the right path?

How to translate from Sub Domain to RESTful urls in ASP.NET MVC Routing

I wonder what options I have in MVC Routing that can redirect/translate the incoming requests to the sub-domain urls and redirect them to the new RESTful scheme.
OLD
http://conv.mc.siteexample.com/v01/?token=AB03959BM23DFC3
http://click.mc.siteexample.com/?cd=1&sd=828&dd=1
NEW
http://siteexample.com/api/uri/conv/?token=AB03959BM23DFC3
http://siteexample.com/api/uri/click/?cd=1&sd=828&dd=1
Also a side note that I am actually using MVC WebAPI Routing, but I am sure that this is not important.
You could take a look at the Url Rewrite Module in IIS. Then inside your Web API application you would simply use the standard routing.

Blogs as Sub Domains in ASP.Net MVC

My blog creates URLs like this:
http://localhost:55649/Blogs/MyBlog
How can I create a sub domain so that it looks like it's hosted on it's own subdomain, like this:
http://myBlog.localhost:55649/
I know I can create a sub domain to redirect to localhost:55649/Blogs/MyBlog, but I want that to be the actual domain. Is this possible?
This is possible in MVC and has been answered before here on SO
See Previous Answer
In order for DNS to work, you will need to setup a wildcard subdomain so that any subdomain request for yourdomain.com will still point to your site. IIS will also need to be configured to listen for any and all request for any subdomain for your site. I cannot answer how to do this as I do not know your hosting configuration.
Probably it is not possible by ASP.NET MVC own possibilities like routing.
You need to create two sites in IIS (one for domain and another for subdomain) pointed to the same directory with site code.
And surely it is not possible with ASP.NET Development Server.
Probably URL Rewrite module would also help you: http://www.iis.net/download/urlrewrite

WCF REST Web API and MVC on same server and port

I'm looking at putting together a REST based system which still has a standard browser style access. My desire is to have both of these on the same machine, but what are my options?
Use IIS to host both the web-site and the REST service (different URIs, e.g. http://mysite.com/ and http://mysite.com/api
Use IIS and some magic I don't yet know to have two domains mapped to the same machine but different services (e.g. http://www.mysite.com and http://api.mysite.com
Combine the two technologies into a single service (that perhaps uses routing tables to direct the requests to MVC or WCF where appropriate).
My preference would be the third option, this would allow me to have a single code-base and single repository accessing. The WCF page on codeplex mentions in its release notes, "not tested with MVC3" - is this suggesting that this is a possible approach?
I'm not keen on using MVC for the REST implementation as it is intended that the majority of interaction with my site goes via API, so I want that as the focus.
I've ported the contact manager to use MVC 3. It definiately works though we've not done exhaustive testing. The one thing in general to cognizant of with regards to web api is that both MVC Routes and Service Route are greedy. If your default route is first then MVC will try to grab your HTTP Service requests. One thing you will want to do is put your Service Route first before your MVC routes. If you run into additional issues, you may need to use custom routing constraints.
In http://webapicontrib.codeplex.com there is a sample that works with MVC 3. It is in the Samples/experimental folder. However, it was built with a custom version of WCF Web API. I don't believe it needs to be though. I've been meaning to get the author of the sample to switch it over.

ASP.Net 4 routing and subdomains

I'm developing a site with ASP.Net 4 which uses routing extensively. it displays pages for each client depending on the route data.
http://localhost/abc/manage/posts/ redirect to posts page of abc client
http://localhost/adidas/manage/posts/ redirects to adidas page.
now i need to do this using the subdomain way like adidas.localhost.com. i searched through SOF and found few solutions using MVC.
URL Routing across multiple subdomains
I have added the required wildcard dns, host file changes etc. and i understand that i need to read the hostheader to to determine the client. my question is where do i have to do this check, as im using routing without MVC i don't use MVC controllers. i need to do with ASP.net 4 routing. can someone give me an idea on this ?

Resources