Monday 14 June 2021

Azure Active Directory single sign-on SSO (SAML Login)

 Step 1:  Open URL: https://portal.azure.com/#home



Step2 : Click Manage Azure Active Director


Step3: Click Enterprise Application

Step 4: New Application


Step 5: You're in the new and improved app gallery experience. Click here to switch back to the legacy app gallery experience.


Step 6: Click non-gallery application


Step 7: Put Application Name and Click ADD

Step 8: Click SSOLogin ( Application Name)
Step 9: Set UP Single sign on
Step 10: 



Step 11: put Entity ID & Assertion Consumer Service URL then click Save.

Step 12: Download Certificate & Metadata XML


Step 13:  Open Visual Studio


Step 14: Click Project
 
Step 15: put certificate file in APP_Data Folder
 
Step 16:  Manage Nuget Package 



Step 17: Browser Search Package : AS.SAMLClient then Click Install

Step 18: Add Default.aspx Page

Step 19: Web.config add AppSetting: 
<appSettings>

    <add key="SmCertificateFile" value="~/App_Data/Certicate.cer"/> // 
    <add key="SSOLoginURL" value="Login URL"/>
    <add key="SSOLogOutURL" value="Logout URL"/>
    <add key="ReturnURL" value="Return URL"/>
    <add key="Issuer" value="Application ID"/>
  </appSettings>




step 20: Default .aspx Code:

 
using System;
using System.Configuration;
 protected void Page_Load(object sender, EventArgs e)
        {
            AccountSettings accountSettings = new AccountSettings
            {
                idp_sso_target_url = ConfigurationManager.AppSettings["SSOLoginURL"]
            };
            string certificatePath = ConfigurationManager.AppSettings["SmCertificateFile"];
            accountSettings.smCertificatePath = Server.MapPath(certificatePath);
            try
            {
                if (Request.Form["SAMLResponse"] == null)
                {
                    AppSettings appSettings = new AppSettings();
                    appSettings.assertionConsumerServiceUrl = ConfigurationManager.AppSettings["ReturnURL"];
                    appSettings.issuer = ConfigurationManager.AppSettings["Issuer"];
                    AS.SAMLClient.Saml.AuthRequest req = new AS.SAMLClient.Saml.AuthRequest(appSettings, accountSettings);
                    Response.Redirect(accountSettings.idp_sso_target_url + "?SAMLRequest=" + System.Web.HttpUtility.UrlEncode(req.GetRequest(AS.SAMLClient.Saml.AuthRequest.AuthRequestFormat.Base64)));
                }
                else
                {
                    AS.SAMLClient.Saml.Response samlResponse = new AS.SAMLClient.Saml.Response(accountSettings);
                    samlResponse.LoadXmlFromBase64(Request.Form["SAMLResponse"]);

                    var response = samlResponse.getAllAttributes();
                    foreach (var assert in response)
                    {
                        Response.Write("<b>" + assert.Key + "</b>:" + assert.Value + "<br>");
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }















Saturday 6 February 2021

List table triggers in SQL Server database

 select schema_name(tab.schema_id) + '.' + tab.name as [table],
    trig.name as trigger_name,
    case when is_instead_of_trigger = 1 then 'Instead of'
        else 'After' end as [activation],
    (case when objectproperty(trig.object_id, 'ExecIsUpdateTrigger') = 1 
            then 'Update ' else '' end
    + case when objectproperty(trig.object_id, 'ExecIsDeleteTrigger') = 1 
            then 'Delete ' else '' end
    + case when objectproperty(trig.object_id, 'ExecIsInsertTrigger') = 1 
            then 'Insert ' else '' end
    ) as [event],
    case when trig.[type] = 'TA' then 'Assembly (CLR) trigger'
        when trig.[type] = 'TR' then 'SQL trigger' 
        else '' end as [type],
    case when is_disabled = 1 then 'Disabled'
        else 'Active' end as [status],
    object_definition(trig.object_id) as [definition]
from sys.triggers trig
    inner join sys.objects tab
        on trig.parent_id = tab.object_id
order by schema_name(tab.schema_id) + '.' + tab.name, trig.name;

Saturday 16 January 2021

Install windows service command line with different name

Install windows service command line with different name

Install Service
SC create MyService binPath= "MyService.exe" DisplayName= "MyService"  

Stop Service
SC STOP MyService

Delete Service
SC DELETE MyService

Tuesday 5 January 2021

SSRS export to excel/Pdf in console application in C#

SSRS (SQL Server Reporting Services) export to excel in console application in C#


Namespace:

using RestSharp;
using RestSharp.Authenticators;
using System;
using System.IO;


   private static void GenerateReport(string strReportPath,string _parameters, string FileName, string FileType = "Excel")
        {
            try
            {
                string strReportPath = strReportPath;//"UserDetails"
                //string FileType = "Excel";
                string URL = ConfigurationManager.AppSettings["ReportServerPath"].ToString() + "?" + strReportPath + "&rs:Command=Render&rs:Format=" + FileType + _parameters;
 
                var client = new RestClient(URL);                
                client.Authenticator = new NtlmAuthenticator(ConfigurationManager.AppSettings["ReportUser"].ToString(), ConfigurationManager.AppSettings["ReportPwd"].ToString());
                var request = new RestRequest(Method.GET);
                Byte[] FileByte = client.DownloadData(request);
 
                ByteToFile(FileName, FileByte, FileType);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        static void ByteToFile(string FileName, Byte[] bytes, string FileType)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "\\Data";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path = AppDomain.CurrentDomain.BaseDirectory + "\\Data\\" + System.DateTime.Now.ToString("yyyyMMdd");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            if (FileType == "Excel")
            {
                FileName += ".xls";
            }
            else
            {
                FileName += ".pdf";
            }
            File.WriteAllBytes(path + "\\"+ FileName, bytes);
        }

Excel Export Example:

GenerateReport("UserDetails", "&From=11-Aug-2020&UpTo=01-Jan-2021", "UserDetails","Excel');

PDF Export Example:

GenerateReport("UserDetails", "&From=11-Aug-2020&UpTo=01-Jan-2021", "UserDetails","Pdf');

Monday 9 November 2020

Try cleaning-up your local repository with

 Try cleaning-up your local repository with:

$ git gc --prune=now

$ git remote prune origin



git diff --name-only "@{3 days ago}" "@{2 days ago}"

Thursday 9 July 2020

Types of SQL Server Backups

Overview
SQL Server offers many options for  creating backups.  In a previous topic, Recovery Models, we discussed what types of backups can be performed based on the recovery model of the database.  In this section we will talk about each of these backup options and how to perform these backups using SSMS and T-SQL.

Explanation
The different types of backups that you can create are as follows:


  • Full backups
  • Differential backups
  • File backups
  • Filegroup backups
  • Partial backups
  • Copy-Only backups
  • Mirror backups
  • Transaction log backups

Thursday 4 June 2020

Live Darshan From Shree Kashi Vishwanath Temple Varanasi

Live Darshan From Shree Kashi Vishwanath Temple Varanasi
(श्री काशी विश्वनाथ मंदिर से लाइव दर्शन )


(courtesy https://bit.ly/3eOFj4R)

Upload valid file in C#

    protected bool CheckFileExtandLength(HttpPostedFile HtmlDocFile)     {         try         {             Dictionary<string, byte[]>...