ASP.NET MVC应用程序中的非标准URL

时间:2022-03-30 04:14:14

I have an ASP.NET MVC application like a bookshelf, that deployed on IIS. To get information from i have to put in browser's address line something like bookshelf.com/book/. What have i do to change url from bookshelf.com/book/ to .bookshelf.com?

我有一个ASP.NET MVC应用程序,如书架,部署在IIS上。要获取信息,我必须在浏览器的地址栏中输入类似于bookshelf.com/book/的信息。我有什么办法将books从bookshelf.com/book/更改为.bookshelf.com?

I try to use Url rewriting on IIS, but nothing be done...

我尝试在IIS上使用Url重写,但没有做任何事情......

Thanks in advance.

提前致谢。

1 个解决方案

#1


1  

What have i do to change url from bookshelf.com/book/ to .bookshelf.com?

我有什么办法将books从bookshelf.com/book/更改为.bookshelf.com?

Configure your default route in Global.asax so that the default controller is Book instead of Home:

在Global.asax中配置默认​​路由,以便默认控制器为Book而不是Home:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Book", action = "Index", id = UrlParameter.Optional }
);

This assumes that you have a BookController and an Index action:

这假设您有BookController和Index操作:

public class BookController: Controller
{
    public ActionResult Index()
    {
        ...
    }
}

Now when someone requests http://bookshelf.com/ this controller action will be executed.

现在当有人请求http://bookshelf.com/时,将执行此控制器操作。

#1


1  

What have i do to change url from bookshelf.com/book/ to .bookshelf.com?

我有什么办法将books从bookshelf.com/book/更改为.bookshelf.com?

Configure your default route in Global.asax so that the default controller is Book instead of Home:

在Global.asax中配置默认​​路由,以便默认控制器为Book而不是Home:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Book", action = "Index", id = UrlParameter.Optional }
);

This assumes that you have a BookController and an Index action:

这假设您有BookController和Index操作:

public class BookController: Controller
{
    public ActionResult Index()
    {
        ...
    }
}

Now when someone requests http://bookshelf.com/ this controller action will be executed.

现在当有人请求http://bookshelf.com/时,将执行此控制器操作。