开发者

Site redirecting to wrong login page on server, but works fine locally

开发者 https://www.devze.com 2023-03-23 02:46 出处:网络
So, I\'m working on an MVC3 site. I\'m developing locally, then the build server runs on check-in, and pushes it to the dev server if the build works.

So, I'm working on an MVC3 site. I'm developing locally, then the build server runs on check-in, and pushes it to the dev server if the build works.

My local box in Win7, with VS2010 SP1 using IIS Express for the local web server. The server Is Win2k8 Server R2. On my local box, the MVC3 package is installed, on the server, I hav开发者_开发技巧e the MVC3 libraries bundled with the app, so I don't have to install them on the box.

Here's where it gets strange. The routes are set up to default to HomeController, which is marked with the [Authorize] attribute, so first thing a non-authenticated user should see is the login page. I'm using Forms Authentication with a rather simple setup:

<authentication mode="Forms">
   <forms loginUrl="~/Auth/LogIn" timeout="2880" />
</authentication>

The only thing different from the default is the URL it redirects to. Now, this works completely fine in IIS express. So I commit, it builds, get pushed to development. The Configuration Editor in IIS Manager confirms that the loginUrl on the server is still ~/Auth/LogIn. This is confirmed directly in the web.config also. But, when I attempt to go to the site, I get redirected to /Account/Login?ReturnUrl=%2f. I know the app is running fine, as if I go to /Auth/Login/ manually, I get the login page, I can log in and use the site.

I've never seen this sort of behavior before, has anyone else encountered it, and how did you fix it?


We had the same problem with the RTM version of MVC 3. Varun's answer was a bit hard for me to follow but ultimately led to the solution. To make this clear for others:

In your Web.config file, you probably already have something like this in the <system.web> section:

<authentication mode="Forms">
  <forms loginUrl="Login/Login" defaultUrl="Home"/>
</authentication>

While this works as expected on a Windows 7 dev machine, for some reason it does not work on a Windows 2008 R2 server (different version of some component? I don't know). To make that work I had to add this line to the <appSettings> section:

<add key="loginUrl" value="Login/Login" />


ScottGu answered a similar question on his blog - this is apparently a bug with the RC2 of MVC 3.

The workaround is to add this entry:

<add key="autoFormsAuthentication" value="false" />

to your section in the web application's root web.config file.

However, this no longer works. Now you have to do the following:

It doesn't work with the RTM any more

You need to add to the appSettings in the Web.Config

The issues is in ConfigUtil in WebMatrix.WebData

private static string GetLoginUrl()
{
    return ConfigurationManager.AppSettings[FormsAuthenticationSettings.LoginUrlKey] ??            FormsAuthenticationSettings.DefaultLoginUrl;

}

staticFormsAuthenticationSettings()
{
    LoginUrlKey = "loginUrl";
    DefaultLoginUrl = "~/Account/Login";
}


I've got several suggestions. They're all from my mind since I can't examine your dev server physically and haven't encountered such an issue. These suggestions might sound silly and could be easily overlooked, but the most frustrating bugs are those that are caused by the obvious reasons we generally don't look for since we jump to the more complex possibilities.

  1. Is there any related setting in the dev server's IIS , on the server level (as opposed to a site level)? Specifically, under Authentication -> Forms Authentication.

  2. Is there any related setting in machine.config on the dev server?

  3. Have you tried to perform full text search on the application's directory on the dev server, looking for, say, "Account"?


If Ofer Zeligs options dry out, Try this :

Find out which is the configuration used while building (or) deploying to server, and check the appropriate web.config transformation files. Or if you are not using web.config transformations, find out how the configuration is maintained for different environments and use that knowledge to see if all the maintained separate configurations ALL HAVE ~/Auth/LogIn in it. There often are separate config files for different environments, and i have seen them go out of sync.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号