IIS / ASP / ASP.net:如何构建网站揭露手机版 [英] IIS/ASP/ASP.net: How to structure web-site to expose mobile version
问题描述
pretend我有一个现有的网站,例如:
Pretend i have an existing web-site, e.g.:
www.stackoverflow.com
www.stackoverflow.com
我现在要公开本网站的移动版本:
i now want to expose a mobile version of this web-site:
m.stackoverflow.com
m.stackoverflow.com
IIS,其主机头名解析,通常需要的要创建两个的web站点:
IIS, with its host-header name resolution, would normally require two web-sites to be created:
- www.stackoverflow.com
- m.stackoverflow.com
除了现在我在IIS两个Web站点。这意味着我必须复制它们之间code /文件。我不需要(我也不希望)复制所有的模式和控制两个web站点之间code。我宁愿有一个网站,公开了手机版。
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.
我的可能的有 m.stackoverflow.com
的默认
页只需执行一个重定向到一个移动目标网页上的真实网站:
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" %>
然后客户端将在(例如) www.stackoverflow.com/mobile/default.aspx
。
这是不是我想要的。我的希望的它似乎他们正在访问 m.stackoverflow.com
。
This isn't what i want. i want it to appear to the browser that they are visiting m.stackoverflow.com
.
所以我的可能的做IIS是有两个主机头名的有一个的IIS网站:
So what i could do in IIS is have two host-header names for one IIS web-site:
- stackoverflow.com
- m.stackoverflow.com
和检查http请求 HOST
标题:
and inspect the http-request HOST
header:
GET http://stackoverflow.com/questions/ViewQuestion.aspx?qid=3623844
Host: stackoverflow.com
诗
GET http://stackoverflow.com/questions/ViewQuestion.aspx?qid=3623844
Host: m.stackoverflow.com
除了现在我所有的我的网站页面必须首先检查主机
属性,然后更改取决于它发现呈现行为。这工作有点好于传统的ASP:
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 %>
但使双视图在一个页面是非常痛苦的。我会的 preFER 的有 ViewQuestion
观点,即致力于呈现出定期或移动视图。
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.
- 不仅我没有的希望的有充分的网页内容发送到基于CSS的移动客户端(浪费带宽和下载速度),然后隐藏内容
- 不是所有的手持设备(如iPhone)履行
媒体=手持
媒体类型
- 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
那么,什么是在接受源 - code和IIS配置最能支持网站的移动版本的组合?
So what is the accepted combination of source-code and IIS configuration that best supports mobile versions of a web-site?
修改一:删除标题参考MVC。不希望人们认为使用一些特殊的MVC框架,因为我的不可以使用任何MVC框架。我使用的ASP / ASP.net
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.
- Redirect移动设备到我的网站 的另一个版本
- How创建asp.NET网站的移动版本?
- 创建网站的移动版本
- What's最有效的方法,为网站的移动版本隐藏内容?
- 一个更好的ASP.NET MVC的移动设备功能的ViewEngine
- Redirect mobile devices to alternate version of my site
- How to create mobile version of asp.NET web site?
- Creating a mobile version of a website
- What's the most efficient way to hide content for a mobile version of a site?
- A Better ASP.NET MVC Mobile Device Capabilities ViewEngine
推荐答案
在MVC,您可以通过覆盖视图引擎刚刚提交手机的看法。我们在3天内创建我们的网站的iPhone版本。
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
这篇关于IIS / ASP / ASP.net:如何构建网站揭露手机版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!