我将我的 MVC 3 应用程序部署到服务器,在解决了与缺少 MVC dll 相关的几个问题(服务器没有安装 MVC)后,它开始给出错误:
Firefox “页面未正确重定向” Chrome “此网页有重定向循环” IE “此页面无法显示”
我发现人们说它与 cookie 有关,但我不明白如何解决这个问题。
我从来没有看到默认页面是否。
我怀疑我的 Global.asax 文件或 Web.Config 有问题。
全球.asax:
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
我的Web.Config中有一部分没有 AppSettings、connectionStrings 和 system.serviceModel:
<system.web>
<compilation debug="true" defaultLanguage="c#" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<customErrors mode="Off">
<error statusCode="404" redirect="/Error/PageNotFound" />
</customErrors>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="UrlRoutingHandler" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
登录页面的索引操作:
public ActionResult Index()
{
if (CurrentAuthenticatedData != null && CurrentAuthenticatedData.User != null)
ViewBag.IsLogin = true;
else
ViewBag.IsLogin = false;
return View();
}
当前已验证数据:
System.Web.Routing.RequestContext Ctx = null;
public AuthenticatedData CurrentAuthenticatedData
{
get
{
AuthenticatedData retval = null;
if (Ctx.HttpContext.User.Identity.IsAuthenticated)
{
retval = (AuthenticatedData)ViewBag.Auth;
}
return retval;
}
}
AuthenticatedData 是一个类,我在其中存储与登录用户相关的几个属性。
最后是我的查看代码:
@{
ViewBag.Title = "Index";
}
<h2>Efetuar Login</h2>
@using (Html.BeginForm())
{
<div style="@(ViewBag.IsLogin??false ? "display: none" : "")">
@Html.ValidationMessage("Error")
<p>Username:<input type="text" name="usr" /></p>
<p>Password:<input type="password" name="pwd" /></p>
<p>
<input type="submit" value="Login" />
</p>
</div>
}
我尝试部署一个虚拟 MVC 应用程序,它可以工作!=/
你能帮助我吗?
谢谢