Archive

Posts Tagged ‘ASP.net’

SharePoint: Using Papercut for testing the email functionality in SharePoint.

October 31, 2014 Leave a comment

In many scenarios while working with SharePoint we may come across requirement to test emails. Like email alerts, emails from workflow, timer jobs or event receivers etc. In my case I need to test emails from Timer job.
While development phase it is not always possible to have a SMTP sever available to test those kind of functionality and in those scenarios Papercut is best utility available for our help. Papercut is a simplified SMTP server designed to only receive messages and serve the purpose of light weight SMTP.
You can use Papercut in .Net development or SharePoint development. You just need to download and install the Papercut on your SharePoint server.

Papercut-v3.1.0-S1
Some points to consider while using Papercut with SharePoint-
1. Papercut is only to receive emails.
2. In case of ASP.Net application provide host=”127.0.0.1″ port=”25″ in web.config file under mailsettings section.
3. For SharePoint, If you have single server farm then you don’t need to worry just install Papercut and set the ‘Outbound SMTP Server’ to localhost or 127.0.0.1 in ‘Configure outgoing e-mail settings’ under central admin, System settings.
4. You can now test by creating simple alert on any list.
5. If you have muti-server farm and testing email from timer job then need to find on which server timer service is running and on that sever you need to install Papercut also give this server IP in ‘Outbound SMTP Server’ in ‘Configure outgoing e-mail settings’ under central admin, System settings.
6. If timer service running on more than one server then make sure port 25 open between those servers to get emails from timer job.
Hope this will help.

Note: complete contribution, development and license rights are with the team who have developed this and as per the http://papercut.codeplex.com/license . This post is just to make readers aware that this kind of tool exists.

Calling different client side function after ASP.net Ajax request completes

April 11, 2012 3 comments

Hi Friends,
While working in ASP.net we come across some situation where we need call custom JavaScript function after Ajax call completes, we can achieve this using add_endRequest as shown in following code –

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

But what in case where we have multiple update panels on the same aspx page?
If we want different action to be performed for each update panel then we need to track the sender of the endRequest and accordingly we can give the call to appropriate JavaScript function.
Following code will show how to achieve this –
In Head tag –

    <script type="text/javascript">

        window.onload = function () { Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); };

        function EndRequestHandler(sender, args)

        {

           // It will get called after each asynchronous postback
           if (sender._postBackSettings.sourceElement.id == '<%= btn_first.ClientID %>')
              alert('Here First update panel\'s request completed...');
        else if (sender._postBackSettings.sourceElement.id == '<%= btn_second.ClientID %>')
              alert('Here Second update panel\'s request completed...');
        }

</script>

In Body following ASP.Net controls available

<asp:ScriptManager runat="server" ID="SCM"></asp:ScriptManager>
    <asp:Panel runat="server" ID="pnl">
    <asp:UpdatePanel runat="server" ID="upanelFirst">
    <ContentTemplate>
    <asp:Button runat="server" ID="btn_first" Text="First" OnClick="testbtn_Click" />

    </ContentTemplate>
    </asp:UpdatePanel>

    <asp:UpdatePanel runat="server" ID="upanelSecond">
    <ContentTemplate>
    <asp:Button runat="server" ID="btn_second" Text="Second" OnClick="testbtn1_Click" />

    </ContentTemplate>
    </asp:UpdatePanel>

    <asp:UpdateProgress runat="server" ID="uprogress">
    <ProgressTemplate>
    Loading...
    </ProgressTemplate>
    </asp:UpdateProgress>
    </asp:Panel>

Now as shown in the example I have checked the id of the sender control i.e. the control who raised the post back.

Happy coding…

Redirect to https:// from http in ASP.net

February 15, 2011 1 comment

Hi Friends,
In some cases if you want to redirect the request from Non-secured to secured page.
Add following code in your page or master page.

if(!Request.IsSecureConnection)
{
string redirectUrl = Request.Url.ToString().Replace("http:", "https:");
Response.Redirect(redirectUrl);
}

This will redirect to same page with HTTPS.

Categories: Asp.net Tags: , , ,