WebPartManager: disable Personalization and still use WebPartManger.AddWebPart()

S

SlimFlem

Is this possible? My entire web site is being built dynamically using
WebPart's and a lot of it will be anonymous. How do I load these parts
dynamically using WebPartManager.AddWebPart() and not use
Personalization. I think I am saying this correctly. When I disable
Personalization in the WebPartManager tag and use AddWebPart(), I am
told Personalization is not enabled....

There is also a defaut Authorization entry in IIS specifying all users,
all verbs. What else am I missing?

Please say so if you need code snippets. Or you can point me to an
article. From what I've been reading, I cannot find what I need.
 
M

Manish Pansiniya

I think it is not possible to enable design mode for Webpartmanager control.
I had same problem and I googled it but could not find a proper solution.
Also on ASP.NET tutorial, they said that you must login to switch to the
design mode.

Thanks
 
S

SlimFlem

Hi maybe you can help with one more thing. I have implemented the
Cookie code in the article, but my Page.User object is always null and
I don't understand why. I haven't done a lot with Forms Authentication
before, but it was my understanding the when placing the .ASPXAUTH
cookie in the Cookies collection, this essentially makes the user
IsAuthenticated = true and the User object not null.

What am I missing. My code is the C# version of the code in the
article. I am doing this in an HttpModule and not in Page_Load(). I
have tried both but it makes no difference. Is there something else I
should be doing to get the User object set and IsAuthenticated to be
true?

Thanks.
 
S

SlimFlem

The only difference between the article and my code is that I have an
IHttpModule that runs first to perform some Url remapping, or not. If
my Url is remapped, I do a Server.Transfer to avoid a duplicate
request, otherwise, the module does nothing and the request happens as
normal.

The module that performs the FormsAuthentication and creates the
HttpCookie runs first followed by the Url remapping IHttpModule.

Is it required to do a Response.Redirect() so the .ASPXAUTH cookie is
recognized and the User object is set?
 
S

SlimFlem

Will a Server.Transfer() break FormsAuthentication? When getting into
the aspx that requires authentication, I see the Cookies are created,
but User is null.

Also, I have merged the authenticaiton code in the branch of the
IHttpModule that performs the potential Url remapping and I do the auth
stuff in that branch.

Any info is appreciated.

Here is my code to create the ticket/cookie:
==============================================

void CreateUserCookie(string UserID)
{
// create the new ticket
FormsAuthenticationTicket ticket = new
FormsAuthenticationTicket(1, UserID, DateTime.Now,
DateTime.Now.AddMinutes(40), false, "roles",
FormsAuthentication.FormsCookiePath);

// encrypt the ticket
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
// create an authentication cookie
HttpCookie ticketCookie = new
HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
_context.Response.Cookies.Add(ticketCookie);
}

=====

After this, I also do a Response.Redirect back to the same Url, with
this being skipped this time by an IF, then Server.Transfer to the
generic aspx loader page that uses WebPart classes dynamically.
 
S

SlimFlem

I got this working. I had to create a FormsIdentity based on the
FormsAuthenticationTicket then use that to create a GenericPrincipal
and attach it to Context.User.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top