为什么我的应用会打开空白页面并且在路由页面之后没有进入任何重定向链接? 我在C#,MVC,Visual Studio 2010上工作
这是我的登录操作:
[HttpGet]
[AllowAnonymous]
public ActionResult Login()
{
return View();
}
[HttpPost]
[AllowAnonymous]
public ActionResult Login(string name, string psw)
{
if ((Membership.ValidateUser(name, psw)) == true)
{
FormsAuthentication.SetAuthCookie(name, false);
if ((Roles.IsUserInRole(name, "Admin")) == true)
{
return this.RedirectToAction("AboutDetails_Admin", "mytask");
}
else if ((Roles.IsUserInRole(name, "People")) == true)
{
return this.RedirectToAction("TMembersDetails_Admin", "mytask");
}
else return View();
}
else return this.RedirectToAction("Register", "Default");
}
这是登录视图:
@{
ViewBag.Title = "Login";
Layout = "~/Views/_LayoutPage1.cshtml";
}
<h2>Login</h2>
<form action="/Default/Login" method="post">
<label>Full Name:</label><input type="text" name="name" /><br />
<label>Password:</label><input type="text" name="psw" /><br />
<input type="submit" />
</form>
这是我的web.config:
enter code here
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="ttt" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
</configuration>
这是我的路线:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace ttt
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
//routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "",
defaults: new { controller = "Default", action = "Index",
id = UrlParameter.Optional }
);
}
}
}
我该怎么做才能让我的索引页面重定向到登录页面,而不是用http://localhost:1889/Default/Login打开空白页
答案 0 :(得分:0)
我发现了错误, 我在Visual Studio 2015中第一次选择新项目它使项目认证:默认为个人,因此在项目运行时会产生空白页面。 当我将身份验证(在第一个中)更改为无身份验证时,它现在可以正常工作。