使DasBlog在移动设备上工作

I was screwing around last night with my Blackberry and was frustrated to see how crappy my blog (and most blogs) looked on a small device.

昨晚我与黑莓(Blackberry)纠缠不清,并沮丧地看到我的博客(和大多数博客)在小型设备上看起来多么糟糕。

So, here's what I did.

所以,这就是我所做的。

I noticed that you can cast the Request.Browser object in ASP.NET to a System.Web.Mobile.MobileCapabilities. In ASP.NET 1.1, this uses the browsercaps section of your machine.config or web.config. In ASP.NET 2.0, the architecture is much cleaner, using .browser files.

我注意到您可以将ASP.NET中的Request.Browser对象转换为System.Web.Mobile.MobileCapabilities。 在ASP.NET 1.1中,这使用了machine.config或web.config的browsercaps部分。 在ASP.NET 2.0中,使用.browser文件可以使体系结构更加整洁。

Since DasBlog compiles under ASP.NET 1.1 and typically runs under 1.1, I'll talk about this in the context of ASP.NET 1.1, but the essence is the same.

由于DasBlog在ASP.NET 1.1下进行编译,并且通常在1.1下运行,因此我将在ASP.NET 1.1的上下文中进行讨论,但是本质是相同的。

There's a property called IsMobileDevice on the MobileCapabilities object that most folks consider useless. That's because the default browser caps stuff with ASP.NET 1.1 is poo. Here's a good explanation:

大多数人认为无用的MobileCapabilities对象上有一个名为IsMobileDevice的属性。 这是因为ASP.NET 1.1的默认浏览器限制了便便。 这是一个很好的解释

Microsoft pawns the job off on Cyscape.com, which doesn't care about doing the world a service (it's busy selling its competing BrowserHawk product instead).  As a result, machine.config is already woefully out-of-date and unaware of newer browsers like Mozilla/Firefox, Netscape 7, Safari, and Konqueror, so it tells Request.Browser that they are "Netscape 5" (though Safari and Konqueror are wholly unrelated rendering engines).

微软在Cyscape.com上取消了这项工作,Cyscape.com不在乎为世界服务(它正忙于出售其竞争产品BrowserHawk产品)。 结果,machine.config已经严重过时,并且没有意识到较新的浏览器,例如Mozilla / Firefox,Netscape 7,Safari和Konqueror,因此它告诉Request.Browser它们是“ Netscape 5”(尽管Safari和Konqueror是完全无关的渲染引擎)。

Cyscape hasn't done the job and instead wants to upsell to their (very capable, but often overkill) application.

Cyscape尚未完成工作,而是想向其应用程序(功能强大,但往往过于杀伤)加价销售。

Instead I Googled around for Browsercaps XML sections...there are many, and they are in various levels of disarray, but this one from last year was pretty darn good. If you're using ASP/PHP the current Patron Saint of BrowserCaps (non-ASP.NET) is Gary Keith. The ASP.NET one from Chris Maunder at CodeProject is also lovely.

取而代之的是,我在Google中搜索Browsercaps XML部分...很多,而且它们处于各种混乱的状态,但是去年的这一部分相当不错。 如果您使用的是ASP / PHP,则BrowserCaps(非ASP.NET)的当前守护神是Gary Keith 。 来自CodeProject的Chris Maunder的ASP.NET也很可爱

DasBlog supports theming, so I added a bare-bones XHTML-ish mobile-friendly theme for small devices - essentially TinyHTML (my term).

DasBlog支持主题设置,因此我为小型设备(本质上是TinyHTML)添加了一个准XHTML风格的移动友好主题。

I added this code to the SharedBasePage where we decide what theme to use:

我将此代码添加到SharedBasePage中,在此我们确定要使用的主题:

//Are we on a Mobile Device? See if we have a mobile theme and use it instead.

//我们在移动设备上吗? 看看我们是否有移动主题,然后改用它。

System.Web.Mobile.MobileCapabilities mobile = (System.Web.Mobile.MobileCapabilities)Request.Browser;

System.Web.Mobile.MobileCapabilities mobile =(System.Web.Mobile.MobileCapabilities)Request.Browser;

if(mobile.IsMobileDevice == true)

如果(mobile.IsMobileDevice == true )

{

{

    theme = themes["mobile"];

theme = themes [“ mobile”];

    if(theme == null)

如果(主题== null )

    {

{

        loggingService.AddEvent(new EventDataItem(EventCodes.Error,

loggingService.AddEvent( new EventDataItem(EventCodes.Error,

            String.Format("If you have a theme called 'mobile' in your themes folder, readers who visit your site via a Mobile Device will automatically get that theme. User-Agent: {0}",Request.UserAgent),

String.Format(“如果您的主题文件夹中有一个名为“移动”的主题,则通过移动设备访问您的网站的读者将自动获得该主题。User-Agent:{0}”,Request.UserAgent),

            String.Empty));

String.Empty));

    }

}

    else

其他

    {

{

        return theme;

返回主题;

    }

}

}

}

...continue on...

...继续...

And boom, shiny, mobile support for this blog. (It is crazy stuff like this at the last minute that keeps 1.9 from being release, but I promise, it's close. For now, remember that unsupported Daily Builds are here: http://blogs.tamtam.nl/paulb/bits/)

并为该博客提供了繁荣,闪亮的移动支持。 (这是在最后一刻像这样疯狂的东西,使1.9无法发布,但我保证已经接近了。现在,请记住,不受支持的Daily Build在这里: http : //blogs.tamtam.nl/paulb/bits/ )

翻译自: https://www.hanselman.com/blog/making-dasblog-work-on-mobile-devices

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值