Monday, November 10, 2014

Logging Utility

Background

Sometimes you need to introduce excessive logging in a workflow, web application, complex runtime application logging is a very important thing in order to identify issues. I have a logger by looking into various loggers available over the web. The sole purpose of this logger for me was to be applied to a workflow which was written in C# using Windows Workflow Foundation.

Logging seems quite easy if it's an application which runs one time or is a sequential one where the rate of concurrent users is less or negligible you just write all the logging lines down in a file and that's all. But imagine when there are multiple people working on an application for which you are logging you will definitely come across the issue of writing to the file when it's already in use.

Implementation Details 


Here are details of the workflow with a test application; I have tried up to 20 threads which are trying to access the file for writing and its working fine.


Monday, March 17, 2014

Handling the UnauthorizedAccessException in SharePoint Visual Web Part


I came across an issue lately where I had to allow different users to access a web part with each having their own permissions set for a document library.

Some of the users might not have access on the web part or even the library that we have configured with this web part to be shown. So in order to by pass the automatically getting redirected to access denied page we need to run the code in this scope


using (new SPSecurity.SuppressAccessDeniedRedirectInScope())
{
   //Your custom code here
}


That's all that helped me get through this painful situation.

Saturday, September 14, 2013

Suppress Javascript Errors

There are times when we see, due to any reason, our javascript in the page starts throwing errors. Hence if some one is browsing the page using Internet Explorer, they might come across the annoying popups if they have configured the Internet settings like that, this is where this Tutorial might come in handy for a few coders like me tackling the situation.

Again it's not a solution it's just a way to handle and tackle the issues, I would still say if you have time in your hand go through your javascript and get it fixed. This snippet must be used if and only if, you are out of time and options.



I hope it gives peace to someone in need!


Wednesday, September 11, 2013

SharePoint 2014 Conference

Dear All,

Microsoft SharePoint conference is back! You can get the details to register on the following link Details

SharePoint Conference offers a wide variety of presentations, labs, certification testing, Q&A sessions, workshops, and networking events for attendees to build their skills and meet other SharePoint professionals. Along with the best new content, industry trends, and product announcements, SharePoint product managers, engineers, and other experts will be answering questions, giving presentations, and hosting discussions

Sunday, September 8, 2013

Custom Document Library Viewer SharePoint 2013 part 1

Lately I came across an interesting task and was able to successfully deliver it. I know that we have a Custom Library Viewer in SharePoint OOTB. I had a different requirement from the one already present in the SharePoint. I had been asked to develop a Custom Document Library Viewer based on Content Types and also display each of the content type in a separate tab.

So, the requirement was something like that for instance in a document library I have 4 different kinds of content types and there are several items in it. I will have to show 4 different tabs and also display the items in each tab using a grid. Interesting isn't it?!

Yea so this gave birth to a new generic web part based on jQuery tabs, and jQGrid. Which is configurable to use any document library, hosted on any website and user can choose which content types to show for a particular library!

Genius isn't it, alright so stay tuned I will be sharing the implementation details in the next post.

CORS support for ASP.NET Web API


CORS (Cross-Origin Resource Sharing) in an ASP.NET Web API 


I have been facing a dreadful issue "access denied access-control-allow-origin not included in response" error whenever I tried to send an AJAX request. I was able to land my call to the web API service and also checked that the Web API service was returning the correct response with correct headers. Still I was unable to find the solution to it and it really got frustrating.

I followed several tutorials on the web to allow the CORS in web API like:

http://aspnetwebstack.codeplex.com/wikipage?title=CORS%20support%20for%20ASP.NET%20Web%20API

then I found this one

http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx

This tutorial here was the most comprehensive one and actually contained everything that we should know about CORS and moved me one step ahead. I was successfully able to send CORS requests on my local machine.

Again this error appeared when I deployed in production and then I had to remove the previous CORS handler. I was back to square one and was really desperate to find a solution because this was happening in production.

Finally, I found the magical lines which did the trick for me. Thanks to http://encosia.com/using-cors-to-access-asp-net-services-across-domains/ article.

<system.webServer>
 <httpProtocol>
  <customHeaders>
   <add name="Access-Control-Allow-Origin" value="*" />
   <add name="Access-Control-Allow-Headers" value="Content-Type" />
  </customHeaders>
 </httpProtocol>
</system.webServer>


I hope it helps someone in need because I definitely know how miserable our life gets if such an issue appears.

Tuesday, July 30, 2013

Ajax call to Page Methods

Folks,

Recently I got to work on a .NET based Security Token Service and faced an issue where I needed to call a web method from with in the page without creating a new session, normally whenever we use ajax call we get a new session which would redirect us back to the login page of the Application as it doesn't know whether the call was from the authenticated user or what.

Anyway, so I hope you all understand the issue. The main purpose of the function was to get the data from the session for a particular key, I know first thing that comes to your mind would be that I must have used

<%=Session['key']%>

Which is what we use all the time but no this time the scenario was different. I had to get the value because I had an Iframe in the page which was changing the value of that particular key. So what I did was, I googled a bit and got to know about PageMethods. So here it is how I used it


Paste this in your form tag:



<asp:ScriptManager ID="ScriptManagerMain" runat="server" EnablePageMethods="true"
        ScriptMode="Release" LoadScriptsBeforeUI="true">
    </asp:ScriptManager>

And use the javascript:

  function onSuccess(data) {
            window.location = data;
        }
        function onFailure(error) {
            window.location = 'where-ever-I-wanted-it-to-go';
        }
        function GetCurrentSessionValue() {
            // call server side method
            PageMethods.GetSessionValue(onSuccess, onFailure);
        }

This is my Code Behind where I wrote this method.

 [WebMethod]
        public static string GetSessionValue()
        {
           return HttpContext.Current.Session["RedirectUrl"].ToString();
        }


I hope it helps. For any query just post a comment and I will get back to you.