如何更改页面asp.net的网址? [英] how to Change the url of page asp.net?

查看:41
本文介绍了如何更改页面asp.net的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题不在于URL重写.

My problem is not about url rewriting.

我想更改浏览器上正在查看的网址.

I want to change the url that is looking on browser.

例如,实际的网址是:

localhost:57358/Admin/news.aspx?Id = 24

localhost:57358/Admin/news.aspx?Id=24

我希望它看起来像

localhost:57358/Admin/SomeContent ....

localhost:57358/Admin/SomeContent....

要实现此目的,我在global.asax中编写了一个代码,但这全都与URL检索有关.

to implement this I wrote a code in my global.asax but it is all about url rewiting.

protected void Application_BeginRequest(object sender, EventArgs e)
{
    string sRequestedURL = Request.Path;
    string url = Request.Url.ToString();
    if (url.Contains("inner.aspx"))
    {
        int id = int.Parse(url.Split('=')[1]);
        ManageNews mn = new ManageNews();
        string title = mn.getTitleByNewsId(id);
        string targetUrl = "~/inner.aspx?Content=" + title;
        Context.RewritePath(targetUrl, false);

    }
}

请帮助我.

推荐答案

也许我没有真正了解您要尝试做的事情,但为什么不使用浏览此处)以实现您想要的功能.这样,您可以在应用程序的开头指定Route并让asp.net处理它.

Maybe I don't really get what you are trying to do but why not use Routing (walk through here) to achieve what you want. This way you can specify the Route in the start of your application and let asp.net handle it.

从链接引用-

ASP.NET路由使您可以使用不必映射到网站中特定文件的URL.由于URL不必映射到文件,因此可以使用描述用户操作的URL,从而使用户更易于理解.

ASP.NET routing enables you to use URLs that do not have to map to specific files in a Web site. Because the URL does not have to map to a file, you can use URLs that are descriptive of the user's action and therefore are more easily understood by users.

例如

 routes.MapPageRoute("SomeContent",
        "Admin/SomeContent"
        "Admin/news.aspx?Id=24");

如果您尝试做更动态的事情,则可以遵循

If you are trying to do something far more dynamic you may be able to follow the same path used here (although that's for MVC, the logic remains the same) where the routing is configured through a database.

这篇关于如何更改页面asp.net的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆