我可以在MVC网站中拥有default.aspx页面吗? [英] Can I have a default.aspx page in an MVC site?

查看:45
本文介绍了我可以在MVC网站中拥有default.aspx页面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有Default.aspx页的旧版WebForms网站,该页在IIS中配置为默认页.因此,当有人访问 mysite.com 时,他们会参见 mysite.com/Default.aspx ,但是地址栏中的网址仅显示 mysite.com .

I've got a legacy WebForms site with a Default.aspx page that's configured in IIS to be the default page. So when someone goes to mysite.com they see mysite.com/Default.aspx, but the url in the address bar only shows the mysite.com.

我已将MVC添加到该站点,并且希望逐步将功能移至MVC.一切正常,但它破坏了根页面:导航到该路由会导致404,因为默认路由与根匹配,并试图路由Home控制器,但没有一个.所以我添加了一个可以做到这一点的东西:

I added MVC to the site, and I want to gradually move functionality to MVC. Everything works, but it broke the root page: navigating to the route caused a 404 because the default route was matching the root and trying to route a the Home controller, but there wasn't one. So I added one that does this:

' GET: /Home
Function Index() As ActionResult
    'jump to the go page
    Return Redirect("/default.aspx")
End Function

这现在可以工作,除了当您导航到路线时,它在地址栏中显示 mysite.com/Default.aspx .

This now works, except that when you navigate to the route, it shows mysite.com/Default.aspx in the address bar.

我想要它:

  • 我无法匹配根路由,让WebForms Default.aspx 页面像以前一样处理
  • 我可以按照现在的方式进行路由,但是可以这样做,以使Default.aspx页面不会显示在地址栏中.

这两种可能吗?

推荐答案

可能.

在路由配置中,使用默认参数删除控制器.从这个:

In your route configuration, remove the controller in the defaults parameter. From this:

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

对此:

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

然后将 Default.aspx 添加到项目根目录

Then add the Default.aspx to your project root

这篇关于我可以在MVC网站中拥有default.aspx页面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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