Hi Joe,
Would like to report 2 bugs when the portal is deployed in virtual directory e.g. localhost/mojoportal:
1) Image cropping does not work when user uploads/changes avatar.
Reason
The bug is inside ImageCropper.ascx.cs.
The image path would become something like "/mojoportal~/Data/Sites/1/useravatars/user1.jpg" ("/mojoportal" is the application context).
The solution is to remove the "~" from the string.
Original Code
private void PopulateControls()
{
if (!sourceExists)
{
pnlCrop.Visible = false;
}
else
{
imgToCrop.ImageUrl = Page.ResolveUrl(fileSystem.FileBaseUrl + sourceImagePath);
}
if (targetExists)
{
pnlCropped.Visible = true;
imgCropped.ImageUrl = Page.ResolveUrl(fileSystem.FileBaseUrl + resultImagePath + "?g=" + Guid.NewGuid().ToString()); //prevent caching with a guid
}
else
{
pnlCropped.Visible = false;
}
}
Fix:
private void PopulateControls()
{
if (!sourceExists)
{
pnlCrop.Visible = false;
}
else
{
if (sourceImagePath.StartsWith("~"))
{
imgToCrop.ImageUrl = Page.ResolveUrl(fileSystem.FileBaseUrl + sourceImagePath.Substring(1) );
}
else
imgToCrop.ImageUrl = Page.ResolveUrl(fileSystem.FileBaseUrl + sourceImagePath);
}
if (targetExists)
{
pnlCropped.Visible = true;
if (resultImagePath.StartsWith("~"))
{
imgCropped.ImageUrl = Page.ResolveUrl(fileSystem.FileBaseUrl + resultImagePath.Substring(1) + "?g=" + Guid.NewGuid().ToString()); //prevent caching with a guid
}
else
imgCropped.ImageUrl = Page.ResolveUrl(fileSystem.FileBaseUrl + resultImagePath + "?g=" + Guid.NewGuid().ToString()); //prevent caching with a guid
}
else
{
pnlCropped.Visible = false;
}
log.Info(" imgToCrop.ImageUrl : " + imgToCrop.ImageUrl );
}
2) Avatar image does not refresh in user profile after uploading a new image.
Reason
The image is cached in the browser.
Original Code in UserProfile.aspx.cs
if ((!allowGravatars)&&(!disableAvatars))
{
if (siteUser.AvatarUrl.Length > 0)
{
imgAvatar.Src = avatarPath + siteUser.AvatarUrl ;
}
.........
Fix
if ((!allowGravatars)&&(!disableAvatars))
{
if (siteUser.AvatarUrl.Length > 0)
{
imgAvatar.Src = avatarPath + siteUser.AvatarUrl + "?g=" + Guid.NewGuid().ToString() ; // prevent caching with a gguid
}
...............................
-Hung