Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 4 MVC4如何设置默认url?_Asp.net Mvc 4_Web Config_Asp.net Mvc Routing - Fatal编程技术网

Asp.net mvc 4 MVC4如何设置默认url?

Asp.net mvc 4 MVC4如何设置默认url?,asp.net-mvc-4,web-config,asp.net-mvc-routing,Asp.net Mvc 4,Web Config,Asp.net Mvc Routing,我正在构建一个MVC4 web应用程序,并希望设置我希望在web应用程序的起点使用的特定URL 所以我改变了RouteConfig.cs中的一些值,如下所示 routes.MapRoute( name: "Default", url: "{action}.mon/{id}", defaults: new { controller = "login", action = "index", id = UrlParameter.Opti

我正在构建一个MVC4 web应用程序,并希望设置我希望在web应用程序的起点使用的特定URL

所以我改变了RouteConfig.cs中的一些值,如下所示

   routes.MapRoute(
          name: "Default",
          url: "{action}.mon/{id}",
          defaults: new { controller = "login", action = "index", id = UrlParameter.Optional }
   );
您可以通知它,但我在操作名称后面加了一个后缀,这样我就可以调用一个控制器,显示类似“index.mon”的URL

若我在URL栏中手动将“index.mon”放在主机地址之后,那个么它就可以正常工作了。 但当应用程序自动启动时,会抛出403.14错误。(“自动启动”在这里的意思是,我通过输入F5键来运行一个临时IIS服务器来运行这个应用程序。)

登录控制器如下所示

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Monarch815MVC.Controllers
{
public class loginController : Controller
{
    //
    // GET: /login/

    public ActionResult index()
    {
        return View();
    }

    public ActionResult loginProcess(string id = "000000", string pass = "example", string scode = "co")
    {
        Dictionary<string, object> sessionData = null;

        String SqlCommand = "USP_LOGIN";

        DataSet UserInfo = dataController.ExecuteDataset(dataController.CONN_STRING, CommandType.StoredProcedure, SqlCommand, arParms);

        if (UserInfo.Tables[0].Rows.Count > 0)
        {
            sessionData = new Dictionary<string, object>();
            for (int i = 0; UserInfo.Tables[0].Rows[0].Table.Columns.Count > i; i++)
            {
                sessionData.Add(UserInfo.Tables[0].Rows[0].Table.Columns[i].Caption, UserInfo.Tables[0].Rows[0].ItemArray[i]);
            }
        }

        return View();
    }
}
}
使用系统;
使用System.Collections.Generic;
使用系统数据;
使用System.Data.Entity;
使用System.Data.OleDb;
使用System.Linq;
使用System.Web;
使用System.Web.Mvc;
名称空间:815MVC.Controllers
{
公共类登录控制器:控制器
{
//
//获取:/login/
公共行动结果索引()
{
返回视图();
}
公共操作结果登录过程(string id=“000000”,string pass=“example”,string scode=“co”)
{
字典sessionData=null;
字符串SqlCommand=“USP\u LOGIN”;
DataSet UserInfo=dataController.ExecuteDataset(dataController.CONN_字符串,CommandType.StoredProcess,SqlCommand,arParms);
if(UserInfo.Tables[0].Rows.Count>0)
{
sessionData=新字典();
对于(int i=0;UserInfo.Tables[0]。行[0]。Table.Columns.Count>i;i++)
{
sessionData.Add(UserInfo.Tables[0]。行[0]。表。列[i]。标题,UserInfo.Tables[0]。行[0]。ItemArray[i]);
}
}
返回视图();
}
}
}
(让我们忘记登录过程,我删除了一些代码。)

我需要在index()或Web.config中返回阶段时做些什么吗?或者,RouteConfig.cs


我必须使用后缀“.mon”来调用控制器。

我可以考虑只使用hack来解决这个问题。您可能希望创建一个虚拟操作,该操作将是默认操作,并且在被命中时将请求重定向到index.mon

我尝试了以下内容,请检查这是否有助于您。谢谢

在路由配置中

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

            routes.MapRoute(
              name: "DefaultX2",
              url: "{action}/{id}",
              defaults: new { controller = "Home", action = "Startup", id = UrlParameter.Optional }
          );
        }
控制器中

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Startup()
        {
            return RedirectToRoute("DefaultY", new {controller = "Home", action = "Index" });
        } 
    }
对我来说,我使用了索引mon。mon不起作用(稍后我将探讨这一点,也许它与静态文件有关),但上面的代码演示了该方法


希望这能有所帮助。

在url的控制器部分包含.mon时,将.mon放在上面就是在告诉路由仅路由。换句话说,你做的与你想要的完全相反。默认操作会转到特定的url,它们是在没有提供url时执行的操作。感谢您的评论,那么我如何设置您上面提到的默认操作?我想让我的应用程序开始使用“localhost/index.mon”如何做到这一点??这就是我要问的:(你没有听我说的。你试图让默认操作做一些他们做不到的事情。默认操作只会说“如果没有url,在这个控制器上执行这个操作方法”,即…如果你说
http://yoursite/
(没有其他内容)。默认操作不会使您重定向到特定的url。路由仅解释当前url并基于它执行操作。默认操作不会生成此类url,我知道了。因此我取消了路由设置中的默认选项。我仍然想知道,要运行我的应用程序,我必须设置什么类型的设置使用“localhost/index.mon”…?需要修改Web.config或其他什么吗?我已经在谷歌上搜索过了,但到目前为止,我只找到了设置起始页的方法:(