C# 页面不是';t在MVC 3部署后正确重定向
我正在将我的MVC 3应用程序部署到服务器上,在解决了与缺少MVC DLL相关的几个问题(服务器没有安装MVC)后,它开始给出一个错误: Firefox“页面未正确重定向” Chrome“此网页具有重定向循环” IE“无法显示此页面” 我发现有人说这与饼干有关,但我不明白如何解决这个问题 我从来没有看到过默认页面 我怀疑我的Global.asax文件或Web.Config有问题 Global.asax:C# 页面不是';t在MVC 3部署后正确重定向,c#,asp.net-mvc,asp.net-mvc-3,C#,Asp.net Mvc,Asp.net Mvc 3,我正在将我的MVC 3应用程序部署到服务器上,在解决了与缺少MVC DLL相关的几个问题(服务器没有安装MVC)后,它开始给出一个错误: Firefox“页面未正确重定向” Chrome“此网页具有重定向循环” IE“无法显示此页面” 我发现有人说这与饼干有关,但我不明白如何解决这个问题 我从来没有看到过默认页面 我怀疑我的Global.asax文件或Web.Config有问题 Global.asax: public class MvcApplication : System.Web.HttpA
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);
}
}
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;
}
}
我的Web.Config中有一部分没有AppSettings、ConnectionString和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>
CurrentAuthenticatedData:
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);
}
}
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>
}
@{
ViewBag.Title=“Index”;
}
Efetuar登录
@使用(Html.BeginForm())
{
@Html.ValidationMessage(“错误”)
用户名:
密码:
}
我尝试部署一个虚拟MVC应用程序,它可以工作=/
你能帮我吗
谢谢您的MVC安装可能有问题。确保正确安装了MVC 我猜你的路线没有正确注册,因此如果你进入应用程序的主页,它会显示404。这将通过web.config中的以下行获取:
<error statusCode="404" redirect="/Error/PageNotFound" />
并将您重定向到该页面,该页面也会抛出404,再次将您重定向到同一页面,依此类推,导致重定向循环
出于调试目的,您可以注释掉该行并检查路由是否已注册。您的MVC安装可能有问题。确保正确安装了MVC 我猜你的路线没有正确注册,因此如果你进入应用程序的主页,它会显示404。这将通过web.config中的以下行获取:
<error statusCode="404" redirect="/Error/PageNotFound" />
并将您重定向到该页面,该页面也会抛出404,再次将您重定向到同一页面,依此类推,导致重定向循环
出于调试目的,您可以注释掉该行并检查路由是否已注册。我发现MVC在my BaseController中运行一个名为Initialize的方法,然后再运行其他方法:
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
...
}
在该方法中,我有一个验证,以了解用户是否已通过身份验证,以及何时未通过身份验证,我将执行会话。放弃()代码>和一件奇怪的事情(我不知道为什么):
它让我陷入无限循环,因为请求页面是MyNewWebsite而不是MyWebSite
很抱歉,感谢您的耐心我发现MVC在我的BaseController中首先运行一个名为初始化的方法:
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
...
}
在该方法中,我有一个验证,以了解用户是否已通过身份验证,以及何时未通过身份验证,我将执行会话。放弃()代码>和一件奇怪的事情(我不知道为什么):
它让我陷入无限循环,因为请求页面是MyNewWebsite而不是MyWebSite
很抱歉,感谢您的耐心正如我所说的“服务器没有安装MVC”,但我复制了正确的dll文件,并在同一个网站上使MVC 3应用程序在服务器上工作(只需将我的应用程序文件替换为新的dummie MVC应用程序文件),它工作正常。评论你建议的那句话,不要在我的问题上取得任何进展。同样的页面出现了,但还是谢谢你。正如我所说的“服务器没有安装MVC”,但我复制了正确的dll文件,我实际上让一个MVC 3应用程序在服务器上工作,在同一个网站上(只需将我的应用程序文件替换为一个新的虚拟MVC应用程序文件),它就工作了。评论你建议的那句话,不要在我的问题上取得任何进展。出现相同的页面,但还是要感谢。你能发回你的索引(操作)方法吗??可能是您的代码正在创建循环。@surajsingh我用这个信息视图编辑了我的第一篇文章,它可能会提供一些想法!你能回发你的索引(行动)方法吗??可能是您的代码正在创建循环。@surajsingh我用这个信息视图编辑了我的第一篇文章,它可能会提供一些想法!