[英]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=1Bta62而example.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.