MVC程序在本地没有问题,但是部署到服务器后老是跳转到Login.aspx页面,但是我的MVC程序中根本没有Login页面,看了一下链接是这样的 htttp://localhost:26290/login.aspx?ReturnUrl=%2f 查看了一下日志,出现了这样的错误
[OS:Windows 7][Browser:Mozilla][User:hwang43]System.Web.HttpException (0x80004005): 未找到路径“/login.aspx”的控制器或该控制器未实现 IController。
在 System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
在 System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
在 System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
在 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
原来他把Login.aspx当作了一个控制器来查找了,但是程序中又没有Login控制器,并且我在程序的Global.asax文件中也已经定义了默认页面的,
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
为什么没有到指定的页面呢,查找了很久,最终找到了一个解决方案,当然方法肯定不止一个,有时问题相似,但不一定就能解决,网上有一个写的也挺好,
比如这个:http://www.cnblogs.com/dudu/archive/2011/10/10/FormsAuthentication_ReturnUrl_AbsoluteUri.html
我的解决方法
第一步:在web.config文件中添加如下代码:
<add key="autoFormsAuthentication" value="false" /> <add key="enableSimpleMembership" value="false"/>
第二步:
在Global.asax文件中添加如下代码:
protected void Application_PostAuthenticateRequest(object sender, EventArgs e) { if (!UrlAuthorizationModule.CheckUrlAccessForPrincipal(Request.AppRelativeCurrentExecutionFilePath, Context.User, Request.RequestType)) { Response.Redirect(String.Format("{0}?ReturnUrl={1}", FormsAuthentication.LoginUrl, Request.Url.AbsoluteUri)); } }
如果你的问题解决了,我很高兴!
如果你的问题依然没有解决,请不要骂我!