Saturday, November 21, 2015

Fix loosing session automatically

A number of things can cause session state to mysteriously disappear.

    Your sessionState timeout has expired
    You update your web.config or other file type that causes your AppDomain to recycle
    Your AppPool in IIS recycles
    You update your site with a lot of files, and ASP.NET proactively destroys your AppDomain to recompile and preserve memory.

-

If you are using IIS 7 or 7.5, here are a few things to look for:

    By default, IIS sets AppPools to turn themselves off after a period of inactivity.
    By default, IIS sets AppPools to recycle every 1740 minutes (obviously depending on your root configuration, but that's the default)
    In IIS, check out the "Advanced Settings" of your AppPool. In there is a property called "Idle Time-out". Set that to zero or to a higher number than the default (20).
    In IIS, check the "Recycling" settings of your AppPool. Here you can enable or disable your AppPool from recycling. The 2nd page of the wizard is a way to log to the Event Log each type of AppPool shut down.

Friday, September 25, 2015

To call a webpage or webservice from stored procedure

First of all run following queries with sys admin rights:
sp_configure 'show advanced options', 1
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1
GO
RECONFIGURE;
GO
sp_configure 'show advanced options', 1
GO
RECONFIGURE;

After successful call then run following query:
Declare @Object as Int;
Declare @ResponseText as Varchar(8000);

Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get',
                 'http://[domain name]/abc.aspx', --Your Web Service Url (invoked)
                 'false'
Exec sp_OAMethod @Object, 'send'
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT

Select @ResponseText

Exec sp_OADestroy @Object

Tuesday, September 22, 2015

Formatting problem with pdf

In telerik export to pdf I faced very different problem with formatting. One of my report on a server and on local end working fine, but on new server it was not working.
On digging to the issue I have found that difference of MS-Office on both server, older one have MS-office 2010 and newer one have another version, then I found that there is absence of font that I set in pdf file. It was Gloucester font.
Later I have installed it separately on windows server, everything works greatly

Monday, August 31, 2015

URL ReWritting and Ajax tool kit

We have to configure the URL Rewriting module in web.config file.

Negate all .axd or .svc or any or any jquery or webservice request or any specif file or URL.

For example..


     
     
       
       
       
     

     
   

   
     
     
       
       
       
       
       
     

     
   

Thursday, August 20, 2015

Export ssl certificate and private key from store for SAML SSO

  1. Click Start, and then click Run....
  2. Type mmc, and then click OK. The Microsoft Management Console (Console) window opens.
  3. In the Console1 window, click the File menu, and then select Add/Remove Snap-in.
  4. In the Add or Remove Snap-in window, select Certificates, and then click Add.
  5. In the Certificates snap-in window, select Computer Account, and then click Next.
  6. In the Select Computer window, select Local Computer, and then click Finish.
  7. In the Add or Remove Snap-in window, click OK.
  8. In the Console1 window, click + to expand the folder.
  9. Right click on certificates and select certificate that you want to export.
  10. Follow the steps choose base 64 and then fill certificate name say "abc.cert", then save the file in your folder.
  11.  Similar to above point now, right click on certificate, select export private key option, then sytem will ask you add a password for that, fill that and note it in separate file also for future usage.
  12. Follow the steps and save .pfx file in your folder.
  13. Click OK.
  14. Close the Console 1 window, and then click No to remove the console settings.
Next we'll discuss SAML SSO implementation from Service provider.

Install SSL certificate on windows server in IIS7

Here are few simple steps to install ssl certificate in IIS7.
  1. Go to  Internet Information Services (IIS) Manager window, select server.
  2. Double click on Server Certificates.
  3. In Actions pane on the right, click on Complete Certificate Request....
  4. To locate your certificate file, click ....
  5. In the Open window, select *.* as your file name extension, select your certificate (it might be saved as a .txt, .cer, or .crt), and then click Open.
  6. In the Complete Certificate Request window, enter a Friendly name for the certificate file, and then click OK.
  7. NOTE: For Wildcard SSL certificates make sure your Friendly Name to matches your Common Name (i.e. *.coolexample.com).
  8. In the Internet Information Services (IIS) Manager window, select the name of the server where you installed the certificate.
  9. Click + beside Sites, select the site to secure with the SSL certificate.
  10. In the Actions panel on the right, click Bindings....
  11. Click Add....
  12. In the Add Site Binding window:
    • For Type, select https.
    • For IP address, select All Unassigned, or the IP address of the site.
    • For Port, type 443.
    • For SSL Certificate, select the SSL certificate you just installed, and then click OK.
  13. Close the Site Bindings window.
  14. Close the Internet Information Services (IIS) Manager window. Your SSL certificate installation is complete.
  15. Double click on ssl settings, select Accept radio button and apply changes, now website will start working with "https"

Thursday, June 18, 2015

TypeError: $.browser is undefined

just put the $.browser code in your js
var matched, browser;

jQuery.uaMatch = function( ua ) {
    ua = ua.toLowerCase();

    var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
        /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
        /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
        /(msie) ([\w.]+)/.exec( ua ) ||
        ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
        [];

    return {
        browser: match[ 1 ] || "",
        version: match[ 2 ] || "0"
    };
};

matched = jQuery.uaMatch( navigator.userAgent );
browser = {};

if ( matched.browser ) {
    browser[ matched.browser ] = true;
    browser.version = matched.version;
}

// Chrome is Webkit, but Webkit is also Safari.
if ( browser.chrome ) {
    browser.webkit = true;
} else if ( browser.webkit ) {
    browser.safari = true;
}

jQuery.browser = browser;

Monday, April 13, 2015

Http handler call from jquery

Generally webmethod call from jquery is very simple and it can be done via following code:
 $.ajax({ type: "POST",
                    url: "Page.aspx/GetDates",
                    data: '{para1:"' + para1Value + '",para2: "' + para2Value + '"}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        alert(response.d);
                    },
                    failure: function (response) {
                        alert(response);
                    }
                });



But same above code will not work in case of httphanlder call. I have found few reasons behind this:
In httphandler we are getting data in form of Request.Params(eg. Request.Param["para1"]) which only supports url encoded data. So json posted data will not work in above code.
So following code can be used instead of above:

$.ajax({
                  type: "POST",
                  url: "Handler.ashx",
                  data: { fName: firstName },
                 // dataType: "json",

                   beforeSend: function (xhr, settings) {
                      //$("[id$=processing]").dialog();
                      alert('st');
                  },
                  success: function (msg) {
                      alert(msg);
                      alert(msg.d);
                  },
                  error: function () {
                      alert("Error");
                  }

              });


See difference no content type and no data type. Thats it!