This is a strange and interesting problem!
First let me explain the scenario. I have a formsAthentication website, which redirects everything to login.aspx unless the user logs in. I also have a logout.aspx. The reason for this is when the last user didnt log out, and the server session is left in an invalid state, the user is redirected to logout.aspx which cleans the session and starts a new one.
Login.aspx.cs (Simplified) >>
protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.User.Identity.IsAuthenticated && Session["FullName"] != null)
Response.Redirect("~/UsersView.aspx");
else if (HttpContext.Current.User.Identity.IsAuthenticated)
Response.Redirect("~/Logout.aspx");
}
Logout.aspx.cs >>
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["Username"]==null) Session["Username"]="Unknown";
EmployeeSystem.Log("Logout.aspx", "User", null, "Logout", null);
Request.Cookies.Clear();
Roles.DeleteCookie();
Session.Clear();
Session.Abandon();
FormsAuthentication.SignOut();
}
catch (Exception ex)
{
}
Response.Redirect("~/Login.aspx");
}
I also have a componentart script handler that integrates all client side resources into one file:
Web.Config >>
<httpHandlers>
<add type="ComponentArt.Web.UI.CallbackHandler,ComponentArt.Web.UI" path="*.aspx" verb="*" />
<add type="ComponentArt.Web.UI.ScriptHandler,ComponentArt.Web.UI" path="ComponentArtScript.axd" verb="*"/>
</httpHandlers>
When I load the application, the side effect is that before the user is authenticated none of the visual UI controls would load!
Further investigation revealed that when the browser requests for ComponentArtScript.axd, it is redirected to the login page and eventually the server dumps the content of the login page instead of the resource!
To solve the problem I tried changing the path="ComponentArtScript.axd" to path="Images/ComponentArtScript.axd" (where the Image location of my site has anonymous access). But that didnt work, the browser is still requesting from the website root.
So I added the following line in web.config under Configuration tag >>
<configuration>
.....
<location path="ComponentArtScript.axd">
<system.web>
<authorization>
<allow users="*"/>
<allow users="?"/>
</authorization>
</system.web>
</location>
.....
</configuration>
And wala! Problem fixed...
If you are aware of any simpler solution please do post. I believe that these sort of things should be highlighted in one consistent documentation. I get this feeling that Component Art documentation is seriously lacking. Information is available but spread across thousands of threads in different dev forums.