简体   繁体   English

没有IIS的ASP.NET 3.5中的URL重写

[英]URL rewriting in asp.net 3.5 withiout IIS

I am working in as asp.net application which is in asp.net 3.5 version. 我正在使用asp.net 3.5版本的asp.net应用程序。 I have a requirement to implement URL rewriting. 我需要实现URL重写。 I have defined 4 pages like 我已经定义了4个页面,例如

www.abc.com/page1.aspx
www.abc.com/page2.aspx
www.abc.com/page3.aspx
www.abc.com/page4.aspx

I want that when user types www.abc.com/language1 then www.abc.com/page1.aspx open. 我希望当用户键入www.abc.com/language1时打开www.abc.com/page1.aspx。 If user types www.abc.com/language2, then www.abc.com/page2.aspx should open. 如果用户键入www.abc.com/language2,则应打开www.abc.com/page2.aspx。

Please suggest a solution to it. 请提出解决方案。

Also, as this site is complete and have links sent through email to users ( and some of the links have querystrings) what is best way to redirect users to new urls without querystrings and generate new links using new pattern ? 另外,由于该站点已经完成,并且具有通过电子邮件发送给用户的链接(有些链接具有查询字符串),什么是将用户重定向到没有查询字符串的新URL并使用新模式生成新链接的最佳方法?

I have gone through followig techniques: 我经历了Followig技术:

http://www.iis.net/downloads/microsoft/url-rewrite ( this is with IIS, can i use it with asp.net 3.5 and without IIS ? ) http://www.iis.net/downloads/microsoft/url-rewrite (这是IIS,我可以在ASP.NET 3.5和IIS中使用它吗?)

ASP.NET URL Rewriting in very easy way ( it is not tested for security issues) 以非常简单的方式进行ASP.NET URL重写 (未经安全性测试)

http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx ( This require existing links to change ? ) http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx (是否需要现有链接才能更改?)

Please suggest 请建议

public class Global : System.Web.HttpApplication
{
    void RegisterRoutes(RouteCollection routes)
    {
        routes.Add(new Route("language2", new PageRouteHandler("~/page2.aspx")));
    }

    protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }
}

您可以在Global.asax文件中的Application_BeginRequest下执行此操作,检查请求是否来自指定的URL,然后将用户重定向到另一个页面,例如:if(Request.Url.ToString()。ToLower()。Contains(“ language1.aspx” ),然后是Response.Redirect(“ Page1.aspx”)。

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

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