Thursday, 20 September 2018

Error Capture in EventLog

CMD Command: regedit
CMD event view short command: eventvwr
The errors occurred in the system are captured in the event log of the server. We can access the event log of the server by typing event viewer in run command of the local system.
Permissions required: need read/full control permission for network service as shown below at the registry on HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog.in order read and write




Call Function:  ErrorLog.trackEventLog("PersonalLoanApplication", ex.ToString(), "error", 0, 0);
C sharp Code:
public class ErrorLog
    {
 public static void trackEventLog(string appName, string errrorMessage, string logType, int eventID = 0, short shortCat = 0)
        {
       
            try
            {
if (!string.IsNullOrEmpty(appName) && !string.IsNullOrEmpty(errrorMessage) && !string.IsNullOrEmpty(logType))
                {
                    if (!EventLog.SourceExists(appName))
                    {
                        EventSourceCreationData eventSourceData = new EventSourceCreationData(appName, appName);
                        EventLog.CreateEventSource(eventSourceData);
                    }

                    using (EventLog myLogger = new EventLog(appName, ".", appName))
                    {
                        if (logType.Trim().ToLower() == "error")
                        {
                            myLogger.WriteEntry(errrorMessage, EventLogEntryType.Error, eventID, shortCat);
                        }
                        else if (logType.Trim().ToLower() == "warning")
                        {
                            myLogger.WriteEntry(errrorMessage, EventLogEntryType.Warning, eventID, shortCat);
                        }
                        else if (logType.Trim().ToLower() == "information")
                        {
                            myLogger.WriteEntry(errrorMessage, EventLogEntryType.Information, eventID, shortCat);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failsafe EventLog");
                //throw ex;
            }
        }

 public static string GetEventLog(string SourceName)
        {
            try
            {
                if (!string.IsNullOrEmpty(SourceName))
                {
                    EventLog myLog = new EventLog();
                    myLog.Log = SourceName;
                    foreach (EventLogEntry entry in myLog.Entries)
                    {
                        string s = entry.Message;
                        s = s + entry.TimeGenerated;
                        s = s + entry.EntryType;
                        s = s + entry.Source;
                        s = s + entry.Index;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return "";
        }
}

Monday, 3 September 2018

Javascript function call on page load and after posback in Update pannel

 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <script type="text/javascript">
  var prm = Sys.WebForms.PageRequestManager.getInstance();
                prm.add_pageLoaded(function (sender, args) {
function abc()
{
alert("pramod");
}

  });// after postback

//onloan
function abc()
{
alert("pramod");
}
</script>
</ContentTemplate>
 </asp:UpdatePanel>

Friday, 31 August 2018

GridView Column show hide on Header Text base

foreach (DataControlField col in gvFCNR.Columns)
                {
                    if (col.HeaderText == "Action")
                    {
                        col.Visible = false;
                    }
                }

Friday, 20 July 2018

How to restrick the script tag in URL cross site scripting

 Active the requestFiltering utility in IIS then put the below tag for  re-stick the script tag in URL

 <system.webServer>
<security>
      <requestFiltering>
        <denyQueryStringSequences>
          <add sequence="&gt;" />
          <add sequence="&lt;" />
        </denyQueryStringSequences>
      </requestFiltering>
    </security>
  </system.webServer>

Monday, 16 July 2018

Give URL path in GridView

URL path in GridView

NavigateUrl='<%# Eval("CRMLeadID", "~/Onlinedocument.aspx?crmleadid={0}") %>'

NavigateUrl='<%# string.Format("~/Onlinedocument.aspx?crmleadId={0}",Eval("Id").ToString()) %>'

Friday, 8 June 2018

2 Second highest salary find sql query

select top 1 * from [dbo].[TblEmployee] where salary in (
select top 2 max(a.salary) from [TblEmployee] a group by a.salary  order by a.salary desc
)
select * from [dbo].[TblEmployee]

Tuesday, 24 April 2018

SP Transaction and insert

  var userAgent = HttpContext.Current.Request.UserAgent.ToLower();
Request.ServerVariables["REMOTE_ADDR"].ToString()
 IF EXISTS(SELECT 1 FROM tblCity WHERE CityName = @CityName )--and fkstateId =@fkstateId )
BEGIN
select 'record already exists.'
END
 else
              begin
               insert into tblCity(CityName,fkstateId)
                                     values(@CityName,@fkstateId)
                  select 'Record added successfully.'
              end  

------------

Begin transaction    
  --  Your Insert / Update Statement Here
  If (@@Error <> 0)   -- Check error
     Begin        
        rollback transaction      
     End
   else
       commit transaction