AllowAnonymousAttribute does not work with content
I have an action in a controller marked with the attribute
[AllowAnonymous] that return a ContentResult. When I call that action, MVC
redirects me to the login page. If I call another action that return a
ViewResult (on the same controller), I receive the page and I'm not being
redirected to the login page (expected behavior).
Here is the action that unexpectly redirects me to the login page:
public ActionResult AngularConfig(int pid, int uid)
{
const string scriptPath = "~/Scripts/config.js";
string config = System.IO.File.ReadAllText(Server.MapPath(scriptPath));
Uri baseUri = Request.Url ?? new
Uri(String.Format("http{0}://www.domain.com/",
Request.IsSecureConnection ? "s" : ""));
config = config.Replace("{{API_KEY}}", Config.ApiKey)
.Replace("{{RECEIVER_PATH}}", new Uri(baseUri,
"/AppReceiver.html").ToString())
.Replace("{{PAGE_SIZE}}",
Config.PageSize.ToString(CultureInfo.InvariantCulture));
return Content(config);
}
I also tried to return a FileResult but the behavior is the exactly the
same. Here is another action that returns a ViewResult without redirecting
me to the login page:
public ActionResult Stream()
{
return View();
}
Is anyone else had this problem already?
No comments:
Post a Comment