在ASP.NET网站中使用friendlyurl [英] Use of friendlyurl in ASP.NET website

查看:346
本文介绍了在ASP.NET网站中使用friendlyurl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net网站上使用friendlyurl来隐藏.aspx扩展名。但它带有移动视图切换功能。并且因为在移动设备上它会给出错误。所以我只是想不使用移动功能。我该怎么办。



我的尝试:



使用在asp.net网站上的Friendlyurl

I am using friendlyurl in my asp.net website for hiding .aspx extension. but it came with mobile viewswitcher feature. and because of this on mobile it give error. So i simply want to do not use mobile feature. what should i do.

What I have tried:

use of Friendlyurl in asp.net website

推荐答案

步骤1,定义一个继承自WebFormsFriendlyUrlResolver的类并覆盖TrySetMobileMasterPage方法,下面的代码供您参考。

Step 1, define a class Inherited from WebFormsFriendlyUrlResolver and override TrySetMobileMasterPage method, Code below is for your reference.
public class MyWebFormsFriendlyUrlResolver : Microsoft.AspNet.FriendlyUrls.Resolvers.WebFormsFriendlyUrlResolver
{
    protected override bool TrySetMobileMasterPage(HttpContextBase httpContext, Page page, String mobileSuffix)
    {
        if (mobileSuffix == "Mobile")
        {
            return false;
        }
        else
        {
            return base.TrySetMobileMasterPage(httpContext, page, mobileSuffix);
        }
    }
}



然后更新RegisterRoutes方法。




Then update the RegisterRoutes method.

public static void RegisterRoutes(RouteCollection routes)
{
    var settings = new FriendlyUrlSettings();
    settings.AutoRedirectMode = RedirectMode.Permanent;
    routes.EnableFriendlyUrls(settings, new MyWebFormsFriendlyUrlResolver());
}


这篇关于在ASP.NET网站中使用friendlyurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆