I was trying to implement Virtual Users in Sitecore and did a small POC to see how virtual users works.
I tried to browse the URL as
8A5DF7E70EF9%7d&Log=true
IN HttpRequestBegin Pipeline after the UserResolver,I have the below processor with the code as :
System.Web.HttpRequest Request = HttpContext.Current.Request;
if (Request.QueryString["Log"] != null && Request.QueryString["Log"].ToString() == "true")
{
//Build Virtual user if the Sitecore User is not authenticated
if (!user.IsAuthenticated)
{
try
{
//Build a testuser in sitecore domain
string userId = string.Format("{0}\\{1}", "extranet", "testadmin");
var scUser = AuthenticationManager.BuildVirtualUser(userId, true);
scUser.Profile.Initialize(userId, true);
scUser.Profile.Save();
scUser.RuntimeSettings.IsAdministrator = true;
scUser.RuntimeSettings.AddedRoles.Add(@"sitecore\Sitecore Client Authoring");
AuthenticationManager.Login(scUser);
}
catch (Exception ex)
{
Log.Error(ex.Message, this);
}
return;
}
}
Here I am building a virtual user and trying to login as this Virtual user.But here instead of logging in ,it always redirect me to login page at http://somesite/sitecore/login?id=%7b110D559F-
DEA5-42EA-9C1C-8A5DF7E70EF9%7d&la=en&fo=%7b110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9%7d&Log=true
But When I try to achieve the same with the help of a custom page as below
I just created a custom page Something.aspx with the code as below:
protected void Page_Load(object sender, EventArgs e)
{
string url = "/sitecore/shell/sitecore/content/Applications/Content Editor.aspx?id=%7b110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9%7d&la=en&fo=%7b110D559F-DEA5-42EA-9C1C-
8A5DF7E70EF9%7d&Log=true";
url = string.IsNullOrEmpty(url) ? "/" : url;
HttpContext.Current.Response.Redirect(url, false);
}
Here I am doing nothing and just redirecting to content editor and when I browse http://somesite/Something.aspx, I am able to logging in to the content editor with the testadmin user that I created?.Can anyone tell
me why this is happening?
In the approach where I browse the site as http://somesite/Something.aspx In the user resolver the user resolved will be extranet\Anonymous and then hits the PageLoad of Something.aspx and does not hits my custom processor (I am controlling this by not passing Log=true and passing this Log=true only in pageload of Something.aspx ) and upon Redirect ,the User in UserResolver is sitecore\Anonymous and then it hits my custom processor and creates the Virtual user and shell site will not redirect to login site instead it open Content Editor. sitecore\Anonymous--Upon Redirection and then logins as the Virtual User
Where as in the approach where I browse the Content Editor directly ,initially user resolved will be sitecore\Anonymous and then it hits my custom processor and creates the Virtual user and shell site will redirect to login site .
Any Idea why this is happening?