简体   繁体   English

当用户仍然看到example.com/1Bta62时,如何将诸如example.com/1Bta62之类的网址重写为example.com/view.aspx?id=1Bta62?

[英]How to rewrite urls such as example.com/1Bta62 to example.com/view.aspx?id=1Bta62 whilst the user still sees example.com/1Bta62?

As part of an url shortening service, I need users to be able to go to an url such as example.com/1Bta62 and end up at example.com/view.aspx?id=1Bta62 whilst the example.com/1Bta62 is maintained in their browser address bar. 作为一个网址缩短服务的一部分,我需要的用户可以去到一个URL,例如example.com/1Bta62 ,并在最终example.com/view.aspx?id=1Bta62example.com/1Bta62保持在他们的浏览器地址栏中。 How can this be done? 如何才能做到这一点?

I am using a windows server (project is C# ASP.NET); 我正在使用Windows服务器(项目为C#ASP.NET); I would prefer to not have to use scripts (ie just something in web.config would be great) but welcome answers of any method. 我希望不必使用脚本(例如,仅使用web.config中的脚本就可以了),但是欢迎使用任何方法的答案。 The url endings such as the one above 1Bta62 are dynamically generated. 网址结尾(例如1Bta62以上的网址)是动态生成的。

Thanks in advance! 提前致谢!

Edit: Has anyone actually managed/knows how to do this with the web.config file - I think it can be done? 编辑:有没有人实际管理过/知道如何使用web.config文件执行此操作-我认为可以完成?

I would recommend Url Rewrite Module , which has been designed to do just that. 我建议使用Url Rewrite Module ,它就是为此目的而设计的。 It's an IIS module that requires no changes to be done to the app. 这是一个IIS模块,不需要对应用程序进行任何更改。

IIS URL Rewrite 2.0 enables Web administrators to create powerful rules to implement URLs that are easier for users to remember and easier for search engines to find. IIS URL Rewrite 2.0使Web管理员可以创建功能强大的规则来实施URL,这些URL易于用户记住,并且易于搜索引擎查找。 By using rule templates, rewrite maps, .NET providers, and other functionality integrated into IIS Manager, Web administrators can easily set up rules to define URL rewriting behavior based on HTTP headers, HTTP response or request headers, IIS server variables, and even complex programmatic rules. 通过使用规则模板,重写映射,.NET提供程序以及集成在IIS管理器中的其他功能,Web管理员可以轻松设置规则,以基于HTTP标头,HTTP响应或请求标头,IIS服务器变量甚至复杂的URL定义URL重写行为。程序规则。 In addition, Web administrators can perform redirects, send custom responses, or stop HTTP requests 此外,Web管理员可以执行重定向,发送自定义响应或停止HTTP请求

Update: 更新:

Take a look at RouteMagic: http://haacked.com/archive/2011/01/30/introducing-routemagic.aspx 看看RouteMagic: http ://haacked.com/archive/2011/01/30/introducing-routemagic.aspx

Please try registering the routes in area registration. 请尝试在区域注册中注册路线。 For eg, 例如

context.MapRoute(
            "Myproject_default",
            "Myproject/{controller}/{action}/{id}",
            new { controller = "Myproject", action = "index", id = UrlParameter.Optional }
        );

暂无
暂无

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

相关问题 如何将www.example.com重定向到example.com? - How to redirect www.example.com to example.com? 如何添加类似于example.com/id的MapRoute - How to add a MapRoute like example.com/id 像http://example.com这样的输入网址在操作输入中更改为http:/example.com - Input URL like http://example.com changes to http:/example.com in action input 如何为GET请求的C#规则重写example.com/123重定向到example.com/default.aspx?pid=123和123是动态更改 - How to rewritten rule for c# for GET request example.com/123 redirect to example.com/default.aspx?pid=123 and 123 is dynamic change 正则表达式可将URL与替换的通配符进行比较(http://example.com/user/*/profile) - Regex to compare URLs with a wildcard that alternates ( http://example.com/user/*/profile ) 如何使用.net查询https安全网址,如https://example.com/send.aspx?msg=hi - how to query a https secured url with .net like https://example.com/send.aspx?msg=hi 特殊控制器和动作的自定义mapRoute在MVC中如下所示:http://example.com/someValue - custom mapRoute for special controller and action to be like this in MVC: http://example.com/someValue 找不到名称为'Address:http://example.com:8123 / blmrg / test_ws / Service1.svc的终结点元素 - Could not find endpoint element with name 'Address:http://example.com:8123/blmrg/test_ws/Service1.svc 路线网址,例如http://www.example.com/{userId} - Route URL such as http://www.example.com/{userId} Nesper 示例添加程序集引用 - 命名空间 com/Support/UpdateEventArgs/ - Nesper example add assembly reference - namespace com / Support / UpdateEventArgs /
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM