Asp.net mvc MVC应用程序运行后的url为Home/Index。如何改变它?
在我运行MVC中的程序后,它的url是Home/Index。在哪里改变这个?Asp.net mvc MVC应用程序运行后的url为Home/Index。如何改变它?,asp.net-mvc,Asp.net Mvc,在我运行MVC中的程序后,它的url是Home/Index。在哪里改变这个? 我想检查用户是否已登录,以便重定向其他页面。如果他没有登录,那么url可以是Home/Index。如果你使用的是MVC,你应该看看如何使用 如果您使用的是forms authentication,则未经身份验证时转到的url将在web.config中设置。如果您使用的是MVC,则应查看使用 如果您使用的是forms authentication(表单身份验证),则在web.config中会设置未经身份验证时转到的url
我想检查用户是否已登录,以便重定向其他页面。如果他没有登录,那么url可以是Home/Index。如果你使用的是MVC,你应该看看如何使用
如果您使用的是forms authentication,则未经身份验证时转到的url将在web.config中设置。如果您使用的是MVC,则应查看使用
如果您使用的是forms authentication(表单身份验证),则在web.config中会设置未经身份验证时转到的url。对于问题的第一部分(路由),请查看默认路由,它通常设置为
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
它位于web应用程序的Global.asax文件中,这就是您看到所看到内容的原因
您确实需要阅读ASP.Net路由-对于问题的第一部分(路由),请查看默认路由,它通常设置为
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
它位于web应用程序的Global.asax文件中,这就是您看到所看到内容的原因
你真的需要仔细阅读ASP.Net路由-你有两个问题 您的应用程序会自动转到
Home/Index
,因此,如果双击Global.asax
文件,您将找到以下代码
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
更改自定义默认值的“Home”和“Index”字符串
现在,根据您的登录要求,您可以离开默认路径并执行以下操作:
public class HomeController
{
public ActionResult Index()
{
if(!Request.IsAuthenticated)//if NOT authenticated
{//go somewhere else
return RedirectToAction(actioName, controllertName);
}
//for logged in users
return View();
}
}
你问了两件事 您的应用程序会自动转到
Home/Index
,因此,如果双击Global.asax
文件,您将找到以下代码
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
更改自定义默认值的“Home”和“Index”字符串
现在,根据您的登录要求,您可以离开默认路径并执行以下操作:
public class HomeController
{
public ActionResult Index()
{
if(!Request.IsAuthenticated)//if NOT authenticated
{//go somewhere else
return RedirectToAction(actioName, controllertName);
}
//for logged in users
return View();
}
}