简体   繁体   English

ASP.Net Web窗体URL路由具有不同URL的同一页面

[英]ASP.Net Web Forms URL routing same page with different URLs

I am trying to make use of URL routing in my web forms application to make urls more user friendly. 我试图在我的Web窗体应用程序中使用URL路由,以使URL更加用户友好。 I would like to use the following mapping for one of my pages: 我想对我的页面之一使用以下映射:

/services --> common/services.aspx
/services/seo --> common/services.aspx#seo
/services/hosting --> common/services.aspx#web-hosting

Can anyone please help me write the correct routing for this scenario? 谁能帮我为这种情况写正确的路由吗? I would basically want to redirect the user to the different sections on the same page with different URLs as listed above. 我基本上希望将用户重定向到同一页面上具有不同URL的上述不同部分。

Some of the URLs which are already working are: 一些已经起作用的URL是:

//About Us
routes.MapPageRoute("", "about", "~/common/about.aspx", false);

//Contact Us
routes.MapPageRoute("", "contact", "~/common/contact.aspx", false);

Only the first one of the following works- 只有以下第一个作品可以-

//Services - works
routes.MapPageRoute("", "services/{service}", "~/common/services.aspx", false);

//does not work
routes.MapPageRoute("", "services/web-development", "~/common/services.aspx#web", false);
routes.MapPageRoute("", "services/seo", "~/common/services.aspx#seo", false);
routes.MapPageRoute("", "services/digital-marketing", "~/common/services.aspx#marketing", false);

For anyone facing similar problem, here's what i did finally. 对于面临类似问题的任何人,这都是我最后要做的。 I set the routing of all Urls to the same page- 我将所有Urls的路由设置为同一页面-

//Services
routes.MapPageRoute("", "services", "~/common/services.aspx", false);
routes.MapPageRoute("", "services/web-development", "~/common/services.aspx", false);
routes.MapPageRoute("", "services/seo", "~/common/services.aspx", false);
routes.MapPageRoute("", "services/digital-marketing", "~/common/services.aspx", false);

And moved the logic to jump to the section of the page to javascript (using jQuery): 并将逻辑跳转到使用javascript的页面部分(使用jQuery):

$(function () {
            if (window.location.href.indexOf("web-development") > 0) {
                $('html,body').animate({ scrollTop: $(".service-web-development").offset().top }, 0);
            }
            else if (window.location.href.indexOf("seo") > 0) {
                $('html,body').animate({ scrollTop: $(".service-seo").offset().top }, 0);
            }
            else if (window.location.href.indexOf("digital-marketing") > 0) {
                $('html,body').animate({ scrollTop: $(".service-marketing").offset().top }, 0);
            }
        });

This checks the url of the page and moves the window location to the appropriate section of the page. 这将检查页面的url,并将窗口位置移动到页面的适当部分。

Web browsers will prevent the server-side (ASP.NET) from reading anything after the # fragment for security reason. 出于安全原因,Web浏览器将阻止服务器端(ASP.NET)在#片段之后读取任何内容。 so you will not be able to communicate between pages unless on the client-side (JavaScript)... 因此,除非在客户端(JavaScript)上,否则您将无法在页面之间进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM