Tuesday, April 28, 2015

iis asp.net security issues to prevent hacking using configuration file settings


1- Prevent X-Frame and enable  X-XSS-Protection
using configuration file settings

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-UA-Compatible" value="IE=edge,chrome=1" />
        <add name="X-Frame-Options " value="DENY" />
        <add name=" X-XSS-Protection" value="1" />
      </customHeaders>
    </httpProtocol>

https://blog.veracode.com/2014/03/guidelines-for-setting-security-headers/

2-prevent X-frame in file global.ascx

  Protected Sub Application_BeginRequest()
        Response.AddHeader("X-Frame-Options", "DENY")
    End Sub

3-

Sunday, April 26, 2015

calendar get year umalqura using c#

 CultureInfo arCulture = new CultureInfo("ar-SA");
        System.Threading.Thread.CurrentThread.CurrentCulture = arCulture;
        arCulture.DateTimeFormat.Calendar = new UmAlQuraCalendar();
        int yearr =arCulture.Calendar.GetYear(DateTime.Now );

Wednesday, April 22, 2015

set master page dynamically to content page according to language value

To set Master Page dynamically according to language value field from cookie for example you should handle the event in  Page_PreInit event before controls rendered for the page

exmaple :

 void Page_PreInit(Object sender, EventArgs e)
    {
        if (Request.Cookies["CurrentLanguage"].Value.ToString().IndexOf("en-") == -1)
            this.MasterPageFile = "~/Print.master";
        else
            this.MasterPageFile = "~/PrintEN.master";
    }

Tuesday, April 21, 2015

sql server pivot table example cross table using to display yearly report

example
BEGIN
DECLARE @YEAR INT;
SET @YEAR = 2014;
WITH BaseQuery AS(
  Select R.OVR_REQUEST_ID AS RID, Month(R.CREATE_DATE) as REQUEST_Month,
   Year(R.CREATE_DATE) as [Year] ,
  C.CATEGORY_NAME
   from OVR_REQUEST R
   inner join OVR_CATEGORIES C on R.CATEGORY_ID =C.CATEGORY_ID
                           
)
                           
SELECT CATEGORY_NAME , [1] AS [January],[2] AS [February],
                           
  [3] AS [March],[4] AS [April],[5] AS [May],[6] AS [June],
                           
  [7] AS [July], [8] AS [August],[9] AS [September],
                           
  [10] AS [October], [11] AS [November],[12] AS [December]
                           
FROM BaseQuery
                           
PIVOT(SUM(RID) FOR REQUEST_Month IN ([1],[2],[3],[4],[5],
                           
  [6],[7],[8],[9],[10],[11],[12])) AS PVT
  WHERE YEAR=@YEAR
                           
ORDER BY January DESC
END



output














Another Example

Select CATEGORY_NAME ,[Year] ,[Month],  sum(OVR_REQUEST_ID) REQUES_TOTAL from
(
   Select R.OVR_REQUEST_ID, Month(R.CREATE_DATE) as [Month], Year(R.CREATE_DATE) as [Year] ,C.CATEGORY_NAME
   from OVR_REQUEST R
   inner join OVR_CATEGORIES C on R.CATEGORY_ID =C.CATEGORY_ID
   --where date >= '2-1-2014' and date <= '2-28-2014'
) as a
Group by   CATEGORY_NAME ,[Year],[Month]




Wednesday, April 15, 2015

asp.net default submit button behavior control using panel

put your search controls inside panel then assign default button for this panel

  <asp:Panel runat="server" ID="pnl_Search" DefaultButton="BTN_SEARCH">

//your controls and buttons
</asp:panel>

asp.net textbox fire button click using jquery function

 <script type="text/javascript">
        $(document).ready(function () {
            $('#<%=TXT_REQUEST_REPORT_NO.ClientID %>').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13') {

                    $("#<%= BTN_SEARCH.ClientID %>").trigger('click');
                    parent.$.colorbox.close();
                  //  return false;
                }
            });
        });
    </script>

Monday, April 6, 2015

sql server close all connections to current database database in use error

use master
ALTER DATABASE mwa SET SINGLE_USER WITH ROLLBACK IMMEDIATE

--do you stuff here

ALTER DATABASE mwa SET MULTI_USER

Friday, April 3, 2015

sql server get stored procedures updated in specific period

use your database
SELECT *
    name,
    create_date,
    modify_date
FROM sys.procedures
WHERE modify_date >= '20150301'



--- get all objects changes in period

SELECT
    *
FROM sys.all_objects
WHERE modify_date >= '20150301'