ASP.NET MVC - Action with parameter is redirecting to login page which shouldn't be
I have a simple action that takes a single paramter as a string, it returns a users profile page which is working fine.
However a user has told me today that nobody can see he's profile unless logged in, it simply redirects to the login page.
I have checked the IIS7 log file, and I can see that it is returning a 302 status and then loads the login page.
Here is the page that doesn't work:
http://www.house-mixes.com/profile/mixchemist/
Here is an example that works fine:
http://www.house-m开发者_开发百科ixes.com/profile/housemixes/
There are no authorize attributes on the action / controller, I do have Helicon Ape installed managing some custom redirects for me, but I have disabled this and still get the same result.
I'm pretty puzzled here at what could cause this only on a certain profile, any ideas?
EDIT:
There is definetly no Authorize attributes at any level, default or custom. My web.config is pretty standard, and I am using MVC2:
<authentication mode="Forms">
<forms cookieless="UseCookies" enableCrossAppRedirects="true" loginUrl="~/Login" name=".ASPXAUTH" slidingExpiration="true" timeout="100000" requireSSL="false" />
</authentication>
Here is my controllers action (only attribute at controller level is [HandleError]):
[Transaction]
[PassParametersDuringRedirect]
[ModelStateToTempData]
[HttpGet]
public ActionResult Index(string artist)
{
Account account = accountTasks.GetProfileByUsername(artist);
if (account == null)
return RedirectToAction<HomeController>(x => x.Index(), null);
var viewModel = Mapper.Map<Account, ProfilePageViewModel>(account);
return View(viewModel);
}
Paul
That definitely looks like an action that requires authentication. No idea where the problem comes from as you haven't shown any code nor explained how your site works and is organized but you may start looking for [Authorize]
attributes (custom or default ones, as well as global action filters if this is an ASP.NET MVC 3 application) as well as <authorization>
sections in your web.configs.
That's absolutely related to some custom code that runs and simply requires authentication in order to access this resource.
PM> Install-Package Glimpse
Use the tools provided by Glimpse Web Debugger to get a very clear idea of what MVC sees.
Found the issue, you was right in saying that there was an Authorize attribute placed on an action inside a controller, the controller was being called due to a Html.RenderAction() inside the View.
The reason it wasn't working for a specific user is because I allow users to add different widgets to their profile to arrange how they choose, it was a certain widget that had the Authorize attribute on.
Thought I would post back the answer in case it throws anyone else off in the future.
精彩评论