asp.net - IIS/ASP/ASP.net : How to structure web-site to expose mobile version

标签 asp.net iis mobile mobile-website

假设我有一个现有的网站,例如:

www.stackoverflow.com



我现在想公开这个网站的移动版本:

m.stackoverflow.com



IIS 及其主机头名称解析,通常需要创建两个网站:
  • www.stackoverflow.com
  • m.stackoverflow.com

  • 除了现在我在 IIS 中有两个网站。这意味着我必须在它们之间复制代码/文件。我不需要(也不想)在两个网站之间复制所有“模型”和“ Controller ”代码。我宁愿拥有一个公开移动版本的网站。

    我可以拥有 default页面在m.stackoverflow.com只需执行重定向到“真实”网站上的移动登录页面:
    m.stackoverflow.com\default.asp :
     <% Response.Redirect "www.stackoverflow.com/mobile" %>
    

    然后客户端将结束(例如)www.stackoverflow.com/mobile/default.aspx .

    这不是我想要的。我希望它在浏览器中显示他们正在访问 m.stackoverflow.com .

    因此,我可以在 IIS 中为一个 IIS 网站设置两个主机头名称:
  • stackoverflow.com
  • m.stackoverflow.com

  • 并检查 http 请求 HOST标题:
    GET https://stackoverflow.com/questions/ViewQuestion.aspx?qid=3623844
    Host: stackoverflow.com
    

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

    除了现在我所有的网站页面必须先检查 Host属性,然后根据它找到的内容更改渲染行为。这在经典的 ASP 中工作得很好:
    ViewQuestion.asp
    
    <% Dim mobileVersion 
    
        ...
    
    If MobileVersion Then
    %>
    <html>
    ...
    </html>
    <% Else %>
    <html>
    ...
    </html>
    <% End If %>
    

    但是在一页中制作双重 View 是非常痛苦的。我宁愿有一个 ViewQuestion View ,专用于显示常规或移动 View 。

    我也知道我不能使用 media=handheld媒体类型。
  • 我不仅不想将“完整”页面内容发送到移动客户端(浪费带宽和下载速度),然后基于 CSS 隐藏内容
  • 并非所有手持设备(例如 iPhone)都遵守 media=handheld媒体类型


  • 那么什么是接受 最能支持网站移动版本的源代码和 IIS 配置的组合?

    编辑一:删除了对 MVC 的标题引用。不希望人们假设使用某些特定的 MVC 框架,因为我是 不是 使用任何MVC框架。我正在使用 ASP/ASP.net。

    也可以看看
  • 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 中,您可以通过覆盖 View 引擎来提交移动 View 。我们在大约 3 天内创建了我们网站的 iphone 版本。

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

    关于asp.net - IIS/ASP/ASP.net : How to structure web-site to expose mobile version,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5278843/

    相关文章:

    javascript - 针对安卓移动设备

    c# - 从异常过滤器重定向

    c# - ASP.NET Core中的授权。对于[Authorize]属性始终为401未经授权

    asp.net - 在应用程序级别之外使用注册为allowDefinition ='MachineToApplication'的节是错误的

    Android 登录 - 最佳实现

    html - 有没有办法限制移动视口(viewport)的大小?

    c# - 将 Response.TransmitFile 用于物理文件不起作用

    静态内容的 IIS7 集成模式中具有角色的 ASP.NET 身份验证

    c# - 如何将 IP 地址绑定(bind)到我的 Azure Web 角色,以便远程计算机可以全局访问 Web API?

    IIS 中的 Apache ProxyPass 和 ProxyPassReverse 等效项