Posts

Showing posts from July, 2009

Detecting ASP.NET Session Timeouts

How Sessions Are Implemented http://aspalliance.com/520_Detecting_ASPNET_Session_Timeouts.all ASP.NET provides a framework for storing data that is specific to an individual user with the Session object. A page can add information to the Session object, and any other page can then retrieve the information for the same user. In order to preserve server memory, ASP.NET implements a rolling timeout mechanism which discards the session information for a user if no request is seen within the timeout period (default 20 minutes which is reset with each request). It is often useful in an ASP.NET site to know for a particular request if the user’s session information is still intact (that a timeout has not occurred). One common need is to be able to inform the user why they lost their session information, by redirecting to a page that describes the timeout amount and how to avoid the problem in the future. Without this technique it is difficult to know if a session variable is not present wheth...

Windows Communication Foundation

Image
(formerly known as Indigo, some people also called it "ServiceModel" because service comes under syste.ServiceModel) What is WCF? •Simply put, a better way for building distributed systems – it’s about messages – not platforms or runtimes •Simplifies development of connected applications through a new service-oriented programming model •Unification of Microsoft Distributed Computing Technologies •Interoperability with Applications Built on Other Technologies Why Need WCF •WCF provides the next generation of distributed communication on the basis of service oriented programming model. • Current distributed system –ASP.NET Web Services (ASMX) :Enables cross platform interoperability –The Microsoft Message Queue (MSMQ) : Enables transaction integration across multiple parties –.NET Remoting: communication with object across application domain boundaries •WCF is all about providing a single programming model that unifies the features of ASMX, MSMQ, Remoting ...

Setting the trust level for newly installed Web Parts

Problem description : Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=1 After installing a new SharePoint Web Part, it is not working and you get an error like Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed. Solutions: 1. Change the trust level for your SharePoint Web Part This means the trust level of your newly installed SharePoint Web Part is not set correctly. To fix this, follow these steps: Start the Visual Studio Command Prompt (in the program group Visual Studio Tools).Go to the directory where the dll is installed (typically c:\Inetpub\wwwroot\wss\VirtualDirectories\80\bin).Run the command gacutil /i newwebpartdll.dll. Run iisreset . Your newly installed SharePoint Web Part will be added to the global assembly cache (GAC) and everything shoul...

Unable to add selected web part(s).

Image
Every once in a while when you create a web part or upgrade web part, or do some of things developers do when developing web parts, there comes the chilling moment, when you see an error message such as the one below: So the question is what we do in this case? Before you hit the discussion boards, or worse, start pulling your hair, here are couple of tips you can use to troubleshoot the issue: 1. Make sure the control is registered as safe in the web.config (...actually the error says what it means, right) 2. Make sure the assembly is accessible and in the [port]bin folder. (obvious, but worth mentioning) 3. Make sure the assembly name in the *.webpart definition file, matches the assembly name in the safe control element in web.config 4. Make sure you don't have more than one *.webpart file for the same web part in the web part catalog. This may happen if you changed the name of the *.webpart file. 5. Restart IIS to start clean. Attach the debugger to the w3wp.exe process and try...

.NET Remoting look

Image
.NET Remoting uses a flexible and extremely extensible architecture. Remoting uses the .NET concept of an Application Domain (AppDomain) to determine its activity. An AppDomain is an abstract construct for ensuring isolation of data and code, but not having to rely on operating system specific concepts such as processes or threads. A process can contain multiple AppDomains but one AppDomain can only exist in exactly one process. If a call from program logic crosses an AppDomain boundary then .NET Remoting will come into place. An object is considered local if it resides in the same AppDomain as the caller. If the object is not in the same appdomain as the caller, then it is considered remote. In .NET remoting, the remote object is implemented in a class that derives from System.MarshalByRefObject . The MarshalByRefObject class provides the core foundation for enabling remote access of objects across application domains. A remote object is confined to the application domain where it is ...

Using ResolveUrl in an HTML Helper

Refer below URL for very nice and clean approach: http://stephenwalther.com/blog/archive/2009/02/18/asp.net-mvc-tip-47-ndash-using-resolveurl-in-an-html.aspx

How to resolve relative url's without ResolveUrl

Sometimes you need to resolve relative url's without ResolveUrl. If the code is executing outside a Control, for example in an IHttpHandler or business layer code somewhere that has no reference to a Control, you can't call Control.ResolveUrl. The System.Web.VirtualPathUtility class has some very useful method for converting from an app relative path to an absolute path: string absoluteUrl = VirtualPathUtility .ToAbsolute(relativeUrl);

SPSecurity.RunWithElevatedPrivileges to update SPRoleAssignment of an SPListItem

When you write custom code in Sharepoint webparts, your code will run with your credentials.Not everybody has Full Control, so when a user has only read rights, the code will throw an access denied error when the code needs access to objects that are not in the scope of the user credentials.... (example: add the username in the ReadBy properties of an item). What you need is impersonation, run your code with the help of a user who has just enough rights to run it. Sharepoint has a built-in function to accomplish this: SPSecurity.RunWithElevatedPrivileges, it runs with the System Account User. Some things you should know when using SPSecurity.RunWithElevatedPrivileges : 1. in the delegate function, you must build a new SPSite/SPWeb object (like SPSite siteColl = new SPSite(App.SITE_COLLECTION_URL)) and you can't use the SPContext.Current.Web, because the SPContext runs with the current context (with current user). 2. Also set the AllowUnsafeUpdates property of the site/web where yo...

One or more field types are not installed properly. Go to the list settings page to delete these fields.

One or more field types are not installed properly. Go to the list settings page to delete these fields. You may recvieve the error "One or more field types are not installed properly. Go to the list settings page to delete these fields." for the following reasons when executing a SPQuery (CAML). 1. You are trying to access a field that the internal name is different from the display name in the CAML query. For example if you renamed Title to something else other than Title. The other thing to note is that if the internal name of a field has a space the space should be delimmited as _x0020_ for each space in the name. If you don't know the internal name or would like to call it based on the friendly name simply use the OM to get it. list.Fields["Display Name"].InternalName.ToString(). 2. If you try to reuse the SPQuery object without reinstianting it using the query = new SPQuery (). If you don't do this it will cause the erro because the SPQuery has prop...

Uploading a File to a SharePoint Site from a Local Folder

This programming task shows how to upload a file to a folder on a SharePoint site from a local folder. The task uses the EnsureParentFolder method to ensure that the destination folder exists. Create a Web application in Visual Studio .NET as described in Creating a Web Application on a SharePoint Site, adding a FormDigest control and a page directive for the Microsoft.SharePoint.WebControls namespace to the .aspx file, as follows: Assembly="Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>Note You can obtain the PublicKeyToken value for the current Windows SharePoint Services deployment from the default.aspx file in the Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\LCID(1033 in English)\STS folder, or from information provided for the Microsoft.SharePoint assembly at Local_Drive:\WINDOWS|WINNT\assembly in Windows Explorer. Add an HtmlInputFile control, a text box, and a button t...

Broken TreeView lines in IE7

ISSUE: Using a TreeView control in a web app. It looks fine in IE6, but in IE7, the vertical lines that appear when you expand a node are broken. There are a few black pixels then a few white pixel then a few black pixels, etc RESOLUTION: This issues seems to be related to xhtml; Page should be HTML 4.0 compliant . Means your aspx page DOCTYPE should have HTML 4.0 Transitional. Let me know if you face any issue.