5

Pretend i have an existing web-site, e.g.:

www.stackoverflow.com

i now want to expose a mobile version of this web-site:

m.stackoverflow.com

IIS, with its host-header name resolution, would normally require two web-sites to be created:

  • www.stackoverflow.com
  • m.stackoverflow.com

Except now i have two web-sites in IIS. This means i have to duplicate code/files between them. i don't need to (nor do i want to) duplicate all the "model" and "controller" code between two web-sites. i would much rather have one web-site that exposes a mobile version.

i could have the default page in m.stackoverflow.com simply perform a redirect to a mobile landing page on the "real" web-site:

m.stackoverflow.com\default.asp:

 <% Response.Redirect "www.stackoverflow.com/mobile" %>

Then the client will end up at (for example) www.stackoverflow.com/mobile/default.aspx.

This isn't what i want. i want it to appear to the browser that they are visiting m.stackoverflow.com.

So what i could do in IIS is have two host-header names for one IIS web-site:

  • stackoverflow.com
  • m.stackoverflow.com

and inspect the http-request HOST header:

GET https://stackoverflow.com/questions/ViewQuestion.aspx?qid=3623844
Host: stackoverflow.com

verses

GET https://stackoverflow.com/questions/ViewQuestion.aspx?qid=3623844
Host: m.stackoverflow.com

Except now my all my web-site pages must first inspect Host attribute, and then change rendering behavior depending on which it finds. This works somewhat well in classic ASP:

ViewQuestion.asp

<% Dim mobileVersion 

    ...

If MobileVersion Then
%>
<html>
...
</html>
<% Else %>
<html>
...
</html>
<% End If %>

But making dual view's in one page is very painful. i would prefer to have a ViewQuestion view, that is dedicated to showing a regular or mobile view.


i also know that i can't use the media=handheld media type.

  • not only do i not want to have "full" page content being sent to mobile clients (wasting their bandwidth and download speed) and then hide content based on CSS
  • not all handhelds (e.g. iPhone) honor the media=handheld media type

So what is the accepted combination of source-code and IIS configuration that best supports mobile versions of a web-site?

Edit One: Removed title reference to MVC. Don't want people to assume the use of some particular MVC framework, since i'm not using any MVC framework. i'm using ASP/ASP.net.

See also

Community
  • 1
  • 1
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • Use responsive layout, its easy and better way. There is about here: http://stackoverflow.com/questions/6844020/way-to-do-content-adaptation-to-mobile – newway Sep 29 '11 at 17:01

3 Answers3

2

In mvc you can just submit mobile views by overriding the view engine. We created an iphone version of our site in about 3 days.

http://www.hanselman.com/blog/ABetterASPNETMVCMobileDeviceCapabilitiesViewEngine.aspx

Code Silverback
  • 3,204
  • 5
  • 32
  • 39
1

You can use virtual directories in IIS to point both applications to the same folders so you only have one copy of your application. This is even easier if your model & controller code is in a separate from your code to produce the view.

cordsen
  • 1,691
  • 12
  • 10
  • What might that look like? Do i create a virtual directory for all folders? – Ian Boyd Jun 01 '11 at 17:47
  • You can leave your main app as is, and create your second application m.my-site.com and create virtual directories for each folder and point them to the folders in your main app. You can actually point the root at the same root as your main app as well. One thing to be aware of, if you change your web.config it will be updated for both apps. Instructions to create virtual folders are here C:\svn\branches\ezprints.com_2010-04-22\EZP\Source\EZP.Printstore.Presentation.Web – cordsen Jun 01 '11 at 19:00
1

You should check out this tool available through the MS Web Platform Installer

URL Rewrite 2.0

Application Request Routing 2.5

Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73