0

我有这样的情况,两个网站使用相同的数据(主版本和移动版本)。因此,在主版本的某些页面中,我有像 www.domain.com/link1 这样的内部链接......但是当移动版本使用相同的超链接时,它将用户上下文引导到主站点,但我需要拦截该请求并处理它在移动版本的情况下将用户重定向到我需要的地方。

假设在 www.domain.com/about/strategy.aspx (webforms)页面的主要版本网站中,我有一个指向 www.domain.com/services/item.aspx?Id=1256 的绝对网址,没关系。但是当我在 mobile.domain.com/about/strategy (mvc) 上获得相同页面时,我想将链接 www.domain.com/services/item.aspx?Id=1256 更改为 mobile.domain.com/services/1256 . 问题是我有超过 10000 个带有绝对 URL 的页面,内容管理器会发疯地管理这个问题。

任何想法?

4

4 回答 4

0

如果您正在寻找 Web 表单中用户友好的 URL,那么答案可能是 URL 重写。

您可以为此功能找到一些第三方/开源 dll。

如果我对您的要求有误,请告诉我。:)

于 2013-03-21T11:27:11.397 回答
0

我已经使用 SQL 替换方法手动替换了数据库中的绝对 URL,例如 www.domain.com/services/service.aspx?Id=1000 变为 /services/service.aspx?Id=1000 。然后使用 Dictionary 实现 RewritingModule。

public class RewritingModule : IHttpModule
    {
        /// <summary>
        /// Инициализация
        /// </summary>
        /// <param name="application"></param>
        public void Init(HttpApplication application)
        {
            application.BeginRequest += ApplicationBeginRequest;
        }

        private static void ApplicationBeginRequest(object sender, EventArgs e)
        {
            var _httpContext = HttpContext.Current;

            foreach (KeyValuePair<string, string> item in DictionaryRewrites)
            {
                var currentUrl = _httpContext.Request.RawUrl;
                string itemKey = item.Key;

                if (currentUrl.Equals(itemKey, StringComparison.OrdinalIgnoreCase))
                {
                    Process301Redirect(_httpContext, item.Value);
                    break;
                }
            }

        }

        private static Dictionary<string, string> DictionaryRewrites = new Dictionary<string, string>() 
        { 
            { "/Services/Pavilions/Item.aspx?ItemID=5", "/exhibitions/pavillions/3/hall4" },
            { "/Services/ConferenceHalls/Item.aspx?ItemID=10127", "/conferences/conferencehalls/1/conferencehall1" }

        };

        /// <summary>
        /// 301 Redirect
        /// </summary>
        /// <param name="context"></param>
        /// <param name="toRedirect"></param>
        private static void Process301Redirect(HttpContext context, string toRedirect)
        {
            var _localizationSettings = EngineContext.Current.Resolve<LocalizationSettings>();
            var _workContext = EngineContext.Current.Resolve<IWorkContext>();
            var _httpContext = HttpContext.Current;
            var _webHelper = EngineContext.Current.Resolve<IWebHelper>();
            string applicationPath = _httpContext.Request.ApplicationPath;

            if (_localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
            {
                toRedirect = toRedirect.AddLanguageSeoCodeToRawUrl(applicationPath, _workContext.WorkingLanguage);
            }

            string str = _webHelper.GetApplicationLocation() + toRedirect;
            context.Response.AddHeader("Location", str);
            context.Response.Status = "301 Moved Permanently";
        }

        public void Dispose()
        {
            //clean-up code here.
        }
    }
于 2013-03-22T05:16:25.073 回答
0

我可以考虑 2 种可能的解决方案,它们都需要 javasctipt:

  1. 您有 js 功能,它将覆盖您页面上的网址
  2. 您有 js 处理程序,它将捕获点击并将用户转发到您的服务器操作,您将在其中将他重定向到您想要的位置。
于 2013-03-21T11:30:41.813 回答
0

你可以看看这篇文章:

http://www.iis.net/learn/extensions/url-rewrite-module/developing-a-custom-rewrite-provider-for-url-rewrite-module

于 2013-03-21T11:28:11.547 回答