Monday, January 23, 2023

localhost site is not running in IIS Server ASP.NET C#

 First solution 

1) Right click on the Website folder in windows explorer or in IIS server

2) Go to security tab  > Click on edit > click on add> Click on advance> Click on find now button> Click on IIS_IUSRS> Clik on ok and than again on ok and grant all the permissions

Second solution

if you find below error

HTTP Error 401.3 - Unauthorized

You do not have permission to view this directory or page because of the access control list (ACL) configuration or encryption settings for this resource on the Web server

1) Open to IIS server

2) Double click on Authentication

3) Click on anonymous authentication> Click on edit and select radio button "application pool identity"


Third solution


> Go to control panel
>Click on turn windows feature on or off
> Click on internet information services(Expand it )
>Click on world wide web services
> Install all the feature cgi, asp etc

Sunday, January 22, 2023

HTTP Hanler in ASP.NET C#

 https://www.c-sharpcorner.com/uploadfile/37db1d/create-your-first-http-handler-in-Asp-Net-3-5/


https://www.msdotnet.co.in/2013/10/how-to-create-http-handler-application.html#.Y8zNn3ZByxU


https://www.c-sharpcorner.com/UploadFile/ca2535/call-generic-handler-using-jquery-in-Asp-Net/


https://www.c-sharpcorner.com/article/http-handlers-in-Asp-Net/

How to call ajax jquery call in every ne seconds javascript - d3.timer function

 https://www.codespeedy.com/call-jquery-ajax-in-every-n-seconds/


https://makitweb.com/how-to-fire-ajax-request-on-regular-interval/


https://www.codespeedy.com/call-jquery-ajax-in-every-n-seconds/


https://stackoverflow.com/questions/5687600/jquery-call-ajax-every-10-seconds


https://stackoverflow.com/questions/2170923/whats-the-easiest-way-to-call-a-function-every-5-seconds-in-jquery


https://www.javatpoint.com/timer-api-in-d3-js

How to get data from API data.gov.in

 https://api.data.gov.in/resource/0568dfb3-44cd-4bab-a826-06c914a7c3e2?api-key=579b464db66ec23bdd000001cdd3946e44ce4aad7209ff7b23ac571b&format=xml


go to this site and you will get many apis

https://data.gov.in/apis



https://api.data.gov.in/resource/3b01bcb8-0b14-4abf-b6f2-c1bfd384ba69?api-key=579b464db66ec23bdd000001cdd3946e44ce4aad7209ff7b23ac571b&format=xml&filters%5Bcountry%5D=India&filters%5Bstate%5D=haryana

performance.now() and data.now in javascript

Saturday, January 21, 2023

AJAX UpdateProgress ASP.NET C# bootstrap masking

 https://www.aspsnippets.com/questions/269449/Hide-Ajax-UpdateProgress-loader-image-after-ResponseEnd-in-ASPNet/


https://www.aspsnippets.com/questions/758411/Hide-UpdateProgress-image-after-download-complete-ResponseEnd-using-C-and-VBNet-in-ASPNet/


https://stackoverflow.com/questions/22242871/load-mask-plugin-for-twitter-bootstrap


we have to use model div and body div etcx.


example

 <div class="modal-header">
        <h1>Processing...</h1>
    </div>
    <div class="modal-body">
        <div class="progress progress-striped active">
            <div class="bar" style="width: 100%;"></div>
        </div>
    </div>

AJAX toolkit timer ASP.NET C# ONTICK - Clock time - time changing every second

ASPX PAGE

   <form id="form1" runat="server">

       

    <asp:ScriptManager runat="server"  OnAsyncPostBackError=></asp:ScriptManager>

    <asp:UpdatePanel runat="server">

    <ContentTemplate>

    <asp:Timer ID="Timer1" runat="server" OnTick="getTime" Interval="1000">

    </asp:Timer>

    <asp:Label runat="server" ID="lbl" />

    </ContentTemplate>

    </asp:UpdatePanel>

    </form>

ASPX.CS

 protected void getTime(object sender, EventArgs e)

    {

         lbl.Text= DateTime.Now.ToString();

//Response.redirect(DateTime.Now.ToString()); /*This will work on refresh of page every second, ie without using update panel, it will work*/



    }


For updatepanel we have to create lable, if we use reponse.redirect it will show error



Login Control Inbuilt ASP.NET C#

 https://learn.microsoft.com/en-us/previous-versions/aspnet/ms178329(v=vs.100)


https://www.c-sharpcorner.com/UploadFile/raj1979/login-control-in-Asp-Net-3-5/

Tuesday, January 10, 2023

Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server’s administrator for additional assistance

 Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server’s administrator for additional assistance


https://www.c-sharpcorner.com/blogs/error-message-4012-unauthorized-logon-failed-due-to-server-config

Asp net web admin files ASP.NET C# Path

 C:\Windows\Microsoft.NET\Framework\v2.0.50727\ASP.NETWebAdminFiles


In the visual studio> First create a website and 

> Click on Website menu

> Click on ASP.NET Configuration and 

> Website will automatically give asp.net admin tools option

> Also we can create database aspnetdb with Aspnet_regsql.exe tool


aspnet_regsql.exe is present in folder C:\Windows\Microsoft.NET\Framework\v2.0.50727\

SQL Server Transaction By Microsoft

  IF( @@TRANCOUNT = 0 )

    BEGIN

    BEGIN TRANSACTION

    SET @TranStarted = 1

    END


COMMIT TRANSACTION


ROLLBACK TRANSACTION


end

Stored Procedure with Paging SQL by Microsoft

 ALTER PROCEDURE [dbo].[aspnet_Membership_GetAllUsers]

    @ApplicationName       nvarchar(256),

    @PageIndex             int,

    @PageSize              int

AS

BEGIN


 DECLARE @PageLowerBound int

    DECLARE @PageUpperBound int

    DECLARE @TotalRecords   int

    SET @PageLowerBound = @PageSize * @PageIndex

    SET @PageUpperBound = @PageSize - 1 + @PageLowerBound


 SELECT @TotalRecords = @@ROWCOUNT


    SELECT u.UserName, m.Email, m.PasswordQuestion, m.Comment, m.IsApproved,

            m.CreateDate,

            m.LastLoginDate,

            u.LastActivityDate,

            m.LastPasswordChangedDate,

            u.UserId, m.IsLockedOut,

            m.LastLockoutDate

    FROM   dbo.aspnet_Membership m, dbo.aspnet_Users u, #PageIndexForUsers p

    WHERE  u.UserId = p.UserId AND u.UserId = m.UserId AND

           p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound

    ORDER BY u.UserName

    RETURN @TotalRecords

END

Thursday, January 5, 2023

Custom Validator ASP.NET C# Server side and client side

Server side

  protected void btnAddNew_Click(object sender, EventArgs e)

        {

            if (CustomValidator1.IsValid == true)

            { // button click logic here

}

}


 protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)

        {

            {

                args.IsValid = true;

                if (int.Parse(txtOpenVacancy.Text) > int.Parse(txtSanctionedStrength.Text))

                {

                    args.IsValid = false;


                    ((CustomValidator)source).IsValid = false;

                    CustomValidator1.ErrorMessage = "Open Vacancy is less than or equal to sanction strength";

                    return;

                }

                else

                {

                    args.IsValid = true;

                }

            }

        }


aspx page code

<asp:TextBox runat="server" ID="txtOpenVacancy" TextMode="Number" CssClass="col-md-12 form-control input-sm" Visible="false" ValidationGroup="addrecord" />

<asp:CustomValidator ID="CustomValidator1" runat="server"  Display="Dynamic" ForeColor="Red" ErrorMessage="" ValidationGroup="addrecord" SetFocusOnError="true" ControlToValidate="txtOpenVacancy" OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator>


Client side


https://stackoverflow.com/questions/29340294/button-click-fires-before-custom-validation-occurs

Wednesday, January 4, 2023

Useful websites

 https://csharp-video-tutorials.blogspot.com/2012/06/part-23-c-tutorial-polymorphism.html

https://www.c-sharpcorner.com/


https://www.aspsnippets.com/


https://www.tutorialsteacher.com/

How to add and remove from LINQ list and add or remove from dropdown list

//Delete from Linq list and add to dropdown list

protected void grdOpenVacancy_RowDeleting(object sender, GridViewDeleteEventArgs e)

        {

   int id = (int)grdOpenVacancy.DataKeys[e.RowIndex].Value;

            DataTable dtOpenVacancy = ViewState["vwOpenVacancy"] as DataTable;

            DataRow dr= dtOpenVacancy.AsEnumerable().Where(a=>a.Field<int>("ID") == id).FirstOrDefault();



            //GridViewRow grdrow = grdOpenVacancy.Rows[e.RowIndex];

            bool i = Repository.DeleteOpenVacancy(id);

            //            ddlCadreType_SelectedIndexChanged(null, null);

            

            if (ViewState["dt2"] != null)

            {

                DataTable dt3 = (DataTable)ViewState["dt2"];

                DataRow workRow = dt3.NewRow();

                // workRow["Institute"] = grdrow.Cells[0].Text;

                workRow["Institute"] = dr["InstituteName"];

                workRow["Discipline"] = dr["disciplineName"];

                workRow["cadrename"] = dr["cadreName"];

                workRow["cadreID"] = dr["cadreID"];

                workRow["SS"] = dr["SanctionedStrength"];

                workRow["IP"] = dr["inposition"];

                workRow["Vacancy"] = dr["vacancy"];

                dt3.Rows.Add(workRow);

                ViewState["dt2"] = dt3;


                //ddlInstitute.SelectedIndex = 0;

                //ddlDiscipline.SelectedIndex = 0;


                //ddlDiscipline.Items.Clear();


                //ddlDiscipline.Items.Insert(0, new ListItem("--Select--", "--Select--"));


                if (ddlInstitute.SelectedIndex > 0)

                {

                    var allDisciplines = dt3.AsEnumerable().Where(p => p.Field<string>("Institute") != null).CopyToDataTable();

                    //var disciplines = allDisciplines.AsEnumerable().Where(s => s.Field<string>("institute") == ddlInstitute.SelectedItem.Text && s.Field<int>("ss") != 0).Select(d => new { discipline = d.Field<String>("discipline") });

                    

                    if (ddlCadreType.SelectedItem.Text == (String)dr["cadrename"] && ddlInstitute.SelectedItem.Text == (String)dr["InstituteName"])

                    {

                        var disciplines = allDisciplines.AsEnumerable().Where(s => s.Field<string>("institute") == dr["InstituteName"].ToString() && s.Field<int>("ss") != 0 && s.Field<string>("cadrename") == dr["cadrename"].ToString()).Select(d => new { discipline = d.Field<String>("discipline") });


                        if (disciplines.Count() > 0)

                        {

                            //JavaScriptSerializer js = new JavaScriptSerializer();


                            ddlDiscipline.DataSource = disciplines;

                            ddlDiscipline.DataValueField = "discipline";

                            ddlDiscipline.DataTextField = "discipline";

                            ddlDiscipline.DataBind();

                            ddlDiscipline.Items.Insert(0, new ListItem("--Select--", "--Select--"));

                        }

                        else

                        {

How to add columns to datatable in ASP.NET C# - with string or int type

 DataTable dt = new DataAccess().Read(procName, param).Tables[0];

            dt.Columns.Add("cadrename", typeof(String));

            dt.Columns.Add("cadreID", typeof(int));

            foreach (DataRow item in dt.Rows)

            {

                item["cadrename"] = ddlCadreType.SelectedItem.Text;

                item["cadreID"] = ddlCadreType.SelectedValue;

            }

How to add row to datatable or how to add row to grid row ASP.NET C#

//datarow and datatable

  protected void grdOpenVacancy_RowDeleting(object sender, GridViewDeleteEventArgs e)

        {

            int id = (int)grdOpenVacancy.DataKeys[e.RowIndex].Value;

            DataTable dtOpenVacancy = ViewState["vwOpenVacancy"] as DataTable;

            DataRow dr= dtOpenVacancy.AsEnumerable().Where(a=>a.Field<int>("ID") == id).FirstOrDefault();



            //GridViewRow grdrow = grdOpenVacancy.Rows[e.RowIndex];

            bool i = Repository.DeleteOpenVacancy(id);

            //            ddlCadreType_SelectedIndexChanged(null, null);

            

            if (ViewState["dt2"] != null)

            {

                DataTable dt3 = (DataTable)ViewState["dt2"];

                DataRow workRow = dt3.NewRow();

                // workRow["Institute"] = grdrow.Cells[0].Text;

                workRow["Institute"] = dr["InstituteName"];

                workRow["Discipline"] = dr["disciplineName"];

                workRow["cadrename"] = dr["cadreName"];

                workRow["cadreID"] = dr["cadreID"];

                workRow["SS"] = dr["SanctionedStrength"];

                workRow["IP"] = dr["inposition"];

                workRow["Vacancy"] = dr["vacancy"];

                dt3.Rows.Add(workRow);

                ViewState["dt2"] = dt3;


// grid row and grid view


//GridViewRow grdrow = grdOpenVacancy.Rows[e.RowIndex];

// workRow["Institute"] = grdrow.Cells[0].Text;

but in this case, grid column should have item template field.

IIS server port range minimum and maximum

 From 1 to 65535

> Open IIS server

> Click on website

> Click on Bindings and change port number

reference:- https://serverfault.com/questions/747835/valid-ranges-for-web-site-ports-in-iis

Session Object reference not set to an instance of an object - ASP.NET C#

 Change Request.QueryString["ii"].ToString() to groupList = (string)(Session["UserGroups"])


Remove ToString() to (string)


refernce:- https://stackoverflow.com/questions/8670020/asp-c-sharp-session-variable-object-reference-not-set-to-an-instance-of-an-o

Monday, January 2, 2023

SQL Server Line numbers

 >Open SQL Server Management Studio.

> Click on Text editor.

> Click on Transact-SQL

> Check on line numbers