jts@pimpdog.com

I'm attempting to create a web part that simply displays the currently signed in user's windows logon details.

The following code builds fine, but when I try to include it in a Sharepoint site, I'm getting the following error message in the code pasted below:

Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Without using the WindowsIdentity object, the code is included in the sharepoint site successfully, so I was wondering if I have to somehow reference the WindowsIdentity object in the web.config for the sharepoint site or similar Any comments greatly appreciated!

#region Includes Section
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Security.Principal;
using System.Security.Permissions;
#endregion

namespace CamdenGroup.Webparts
{
public class SigninInfo : System.Web.UI.WebControls.WebParts.WebPart
{
protected override void CreateChildControls()
{
Label aspLabel;
WindowsIdentity ident;

ident = WindowsIdentity.GetCurrent();
aspLabel = new Label();

aspLabel.Enabled = true;
aspLabel.Visible = true;
aspLabel.EnableViewState = true;
aspLabel.Text = ident.Name;
aspLabel.Font.Name = "Arial Unicode MS";
aspLabel.Font.Size = FontUnit.XSmall;
aspLabel.ForeColor = System.Drawing.Color.Blue;

// Add these details to our custom control collection
Controls.Add(aspLabel);
}

public override void RenderControl(HtmlTextWriter writer)
{
RenderChildren(writer);
}
}
}

any ideas



Re: SharePoint - Development and Programming Web Part security permissions problem

Stefan Keir Gordon

Get the identity this way instead:

HttpContext.Current.User.Identity.Name.ToString();




Re: SharePoint - Development and Programming Web Part security permissions problem

Supernova2

How about password I tried the following code

System.Net.CredentialCache.DefaultNetworkCredentials.Password

and received a similar error

Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

Even I put

<IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="UnmanagedCode, ControlThread"
/>

in the wss_minimaltrust.config, I still got the permission error.

Any help to resolve the permission issue or an alternate way to get the password is highly appreciated.





Re: SharePoint - Development and Programming Web Part security permissions problem

Supernova2

This will get the user name. However, I need a way to get the password. Is there an alternative

Thanks.





Re: SharePoint - Development and Programming Web Part security permissions problem

Joe Albrecht

I had a similar problem when trying to connect to a database from my web part.

"Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

To resolve this Microsoft had me modify the web.config in the root where your webpart bin folder is running, and change the following:

<trust level="WSS_Minimal" originUrl="" />

to

<trust level="WSS_Medium" originUrl="" />

This resolved my permissions issue.

Hope this helps.