Tuesday 21 April 2020

Optimization in MVC


  1. Optimization is the technique that is used to reduce the size of CSS and Script in bundleConfig.cs
  2. It make bundle compact and smaller in size.
  3. optimization work in release mode by default it is disable in debug mode.


Syntax Of optimization:-  this syntax is used in the global.asax. we can enable or disable the optimization with the help to set as true or false.

  public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            System.Web.Optimization.BundleTable.EnableOptimizations = false;
        }
    }

Monday 20 April 2020

How to download SSRS report in Excel in Core asp.net with Angularjs














This the demo how to download the ssrs report in Core asp.net.


Export.cshtml:- in this page copy in page the code

@{
    ViewData["Title"] = "Export";
}

<h1>Export</h1>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script>
    var app = angular.module('DemoApp', []);
    app.controller('DemoController'function ($scope, $window) {
        $scope.export = function () {
            var path = "https://localhost:44342/Home/ExportReport?id=1";
            $window.location.href = path
        }
    });
</script>
<div ng-app="DemoApp" ng-controller="DemoController">
    <a style="cursor:pointer;color:blue" ng-click="export()">Export Report</a>
</div>


Controller Page:-

ServerName :- change the name with your server name where you put your Report.
ProjectName:- Change the name with your project name.
ReportName:- change with your report name that you give.

        public IActionResult Export()
        {
            return View();
        }

        public ActionResult ExportReport(string id)
        {
          string reportserver = "http://ServerName";
string url = string.Format("{0}/ReportServer/Pages/ReportViewer.aspx?/ProjectName/ReportName&rs:Command=Render&rs:Format=EXCELOPENXML&rc: id={1}", reportserver,  id);
           return Redirect(url);
        }







Thursday 5 December 2019

Failed to load resource: the server responded with a status of 404 (File not found) for image

If the image not find set the default image.

Use this:-
onerror="this.onerror=null; this.src='../images/Default.png'"

Example:-

 <img  src="images.png" alt="User Image" onerror="this.onerror=null; this.src='Default.png'" >

Monday 30 September 2019

Error Logger in .net Core

To configuring Elmah follow the following steps in the Code:

1. Start the NuGet Solution .
2. Download the 2 package ElmahcoreElmahCore.Sql
    as shown in the image

















3. Open the Startup.cs Page
    Add using ElmahCore;
           using ElmahCore.Sql;
    directives in the top of the page.

4. In the ConfigureServices method add the following code.
    
            services.AddElmah<SqlErrorLog>(options =>
            {
                options.ConnectionString = AppSetting.ConnectionString;
            });

5. In the Configure method, add the following code:

app.UseElmah();


In the SQL Execute the following Query:-

1. Create a table to capture the Error

/****** Object: Table [dbo].[ELMAH_Error] Script Date: 9/5/2019 2:49:51 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ELMAH_Error]( [ErrorId] [uniqueidentifier] NOT NULL, [Application] [nvarchar](60) NOT NULL, [Host] [nvarchar](50) NOT NULL, [Type] [nvarchar](100) NOT NULL, [Source] [nvarchar](60) NOT NULL, [Message] [nvarchar](500) NOT NULL, [User] [nvarchar](50) NOT NULL, [StatusCode] [int] NOT NULL, [TimeUtc] [datetime] NOT NULL, [Sequence] [int] IDENTITY(1,1) NOT NULL, [AllXml] [ntext] NOT NULL, CONSTRAINT [PK_ELMAH_Error] PRIMARY KEY NONCLUSTERED ( [ErrorId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO ALTER TABLE [dbo].[ELMAH_Error] ADD CONSTRAINT [DF_ELMAH_Error_ErrorId] DEFAULT (newid()) FOR [ErrorId] GO /****** Object: StoredProcedure [dbo].[ELMAH_GetErrorsXml] Script Date: 9/5/2019 2:49:53 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO


2. Execute the blow Procedure

CREATE PROCEDURE [dbo].[ELMAH_GetErrorsXml] ( @Application NVARCHAR(60), @PageIndex INT = 0, @PageSize INT = 15, @TotalCount INT OUTPUT ) AS SET NOCOUNT ON DECLARE @FirstTimeUTC DATETIME DECLARE @FirstSequence INT DECLARE @StartRow INT DECLARE @StartRowIndex INT SELECT @TotalCount = COUNT(1) FROM [ELMAH_Error] WHERE [Application] = @Application -- Get the ID of the first error for the requested page SET @StartRowIndex = @PageIndex * @PageSize + 1 IF @StartRowIndex <= @TotalCount BEGIN SET ROWCOUNT @StartRowIndex SELECT @FirstTimeUTC = [TimeUtc], @FirstSequence = [Sequence] FROM [ELMAH_Error] WHERE [Application] = @Application ORDER BY [TimeUtc] DESC, [Sequence] DESC END ELSE BEGIN SET @PageSize = 0 END -- Now set the row count to the requested page size and get -- all records below it for the pertaining application. SET ROWCOUNT @PageSize SELECT errorId = [ErrorId], application = [Application], host = [Host], type = [Type], source = [Source], message = [Message], [user] = [User], statusCode = [StatusCode], time = CONVERT(VARCHAR(50), [TimeUtc], 126) + 'Z' FROM [ELMAH_Error] error WHERE [Application] = @Application AND [TimeUtc] <= @FirstTimeUTC AND [Sequence] <= @FirstSequence ORDER BY [TimeUtc] DESC, [Sequence] DESC FOR XML AUTO



CREATE PROCEDURE [dbo].[ELMAH_GetErrorXml]

(

    @Application NVARCHAR(60),
    @ErrorId UNIQUEIDENTIFIER
)
AS

    SET NOCOUNT ON

    SELECT 
        [AllXml]
    FROM 
        [ELMAH_Error]
    WHERE
        [ErrorId] = @ErrorId
    AND
        [Application] = @Application



CREATE PROCEDURE [dbo].[ELMAH_LogError]

(

    @ErrorId UNIQUEIDENTIFIER,
    @Application NVARCHAR(60),
    @Host NVARCHAR(30),
    @Type NVARCHAR(100),
    @Source NVARCHAR(60),
    @Message NVARCHAR(500),
    @User NVARCHAR(50),
    @AllXml NTEXT,
    @StatusCode INT,
    @TimeUtc DATETIME
)
AS

    SET NOCOUNT ON

    INSERT
    INTO
        [ELMAH_Error]
        (
            [ErrorId],
            [Application],
            [Host],
            [Type],
            [Source],
            [Message],
            [User],
            [AllXml],
            [StatusCode],
            [TimeUtc]
        )
    VALUES
        (
            @ErrorId,
            @Application,
            @Host,
            @Type,
            @Source,
            @Message,
            @User,
            @AllXml,
            @StatusCode,
            @TimeUtc
        )

To check its woking or not create exception use this code:
app.Run(async (context) =>
{ await context.Response.WriteAsync("Hello World!"); int[] numbers = new int[5]; await context.Response.WriteAsync(numbers[6].ToString()); });

Use Query in SQL

SELECT * FROM dbo.ELMAH_Error

Thursday 5 September 2019

Configuring Elmah for use with ASP.NET Core

To configuring Elmah follow the following steps in the Code:

1. Start the NuGet Solution .
2. Download the 2 package ElmahcoreElmahCore.Sql
    as shown in the image

















3. Open the Startup.cs Page
    Add using ElmahCore;
           using ElmahCore.Sql;
    directives in the top of the page.

4. In the ConfigureServices method add the following code.
    
            services.AddElmah<SqlErrorLog>(options =>
            {
                options.ConnectionString = AppSetting.ConnectionString;
            });

5. In the Configure method, add the following code:

app.UseElmah();


In the SQL Execute the following Query:-

1. Create a table to capture the Error

/****** Object: Table [dbo].[ELMAH_Error] Script Date: 9/5/2019 2:49:51 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ELMAH_Error]( [ErrorId] [uniqueidentifier] NOT NULL, [Application] [nvarchar](60) NOT NULL, [Host] [nvarchar](50) NOT NULL, [Type] [nvarchar](100) NOT NULL, [Source] [nvarchar](60) NOT NULL, [Message] [nvarchar](500) NOT NULL, [User] [nvarchar](50) NOT NULL, [StatusCode] [int] NOT NULL, [TimeUtc] [datetime] NOT NULL, [Sequence] [int] IDENTITY(1,1) NOT NULL, [AllXml] [ntext] NOT NULL, CONSTRAINT [PK_ELMAH_Error] PRIMARY KEY NONCLUSTERED ( [ErrorId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO ALTER TABLE [dbo].[ELMAH_Error] ADD CONSTRAINT [DF_ELMAH_Error_ErrorId] DEFAULT (newid()) FOR [ErrorId] GO /****** Object: StoredProcedure [dbo].[ELMAH_GetErrorsXml] Script Date: 9/5/2019 2:49:53 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO


2. Execute Procedure the blow Procedure

CREATE PROCEDURE [dbo].[ELMAH_GetErrorsXml] ( @Application NVARCHAR(60), @PageIndex INT = 0, @PageSize INT = 15, @TotalCount INT OUTPUT ) AS SET NOCOUNT ON DECLARE @FirstTimeUTC DATETIME DECLARE @FirstSequence INT DECLARE @StartRow INT DECLARE @StartRowIndex INT SELECT @TotalCount = COUNT(1) FROM [ELMAH_Error] WHERE [Application] = @Application -- Get the ID of the first error for the requested page SET @StartRowIndex = @PageIndex * @PageSize + 1 IF @StartRowIndex <= @TotalCount BEGIN SET ROWCOUNT @StartRowIndex SELECT @FirstTimeUTC = [TimeUtc], @FirstSequence = [Sequence] FROM [ELMAH_Error] WHERE [Application] = @Application ORDER BY [TimeUtc] DESC, [Sequence] DESC END ELSE BEGIN SET @PageSize = 0 END -- Now set the row count to the requested page size and get -- all records below it for the pertaining application. SET ROWCOUNT @PageSize SELECT errorId = [ErrorId], application = [Application], host = [Host], type = [Type], source = [Source], message = [Message], [user] = [User], statusCode = [StatusCode], time = CONVERT(VARCHAR(50), [TimeUtc], 126) + 'Z' FROM [ELMAH_Error] error WHERE [Application] = @Application AND [TimeUtc] <= @FirstTimeUTC AND [Sequence] <= @FirstSequence ORDER BY [TimeUtc] DESC, [Sequence] DESC FOR XML AUTO



CREATE PROCEDURE [dbo].[ELMAH_GetErrorXml]
(
    @Application NVARCHAR(60),
    @ErrorId UNIQUEIDENTIFIER
)
AS

    SET NOCOUNT ON

    SELECT 
        [AllXml]
    FROM 
        [ELMAH_Error]
    WHERE
        [ErrorId] = @ErrorId
    AND
        [Application] = @Application



CREATE PROCEDURE [dbo].[ELMAH_LogError]
(
    @ErrorId UNIQUEIDENTIFIER,
    @Application NVARCHAR(60),
    @Host NVARCHAR(30),
    @Type NVARCHAR(100),
    @Source NVARCHAR(60),
    @Message NVARCHAR(500),
    @User NVARCHAR(50),
    @AllXml NTEXT,
    @StatusCode INT,
    @TimeUtc DATETIME
)
AS

    SET NOCOUNT ON

    INSERT
    INTO
        [ELMAH_Error]
        (
            [ErrorId],
            [Application],
            [Host],
            [Type],
            [Source],
            [Message],
            [User],
            [AllXml],
            [StatusCode],
            [TimeUtc]
        )
    VALUES
        (
            @ErrorId,
            @Application,
            @Host,
            @Type,
            @Source,
            @Message,
            @User,
            @AllXml,
            @StatusCode,
            @TimeUtc
        )

To check its woking or not create exception use this code:
app.Run(async (context) =>
{ await context.Response.WriteAsync("Hello World!"); int[] numbers = new int[5]; await context.Response.WriteAsync(numbers[6].ToString()); });

Use Query in SQL

SELECT * FROM dbo.ELMAH_Error

The breakpoint will not currently be hit. No symbols have been loaded for this document

Solution of this error :-

Change the build configuration "Release" to "Debug" Mode.






HttpContext.Current.User.Identity.Name returns null or empty string

This error come due to authentication mode problem.

To correct this  error follow the following step:
  1. Select your project.
  2. press F4.
  3. the screen will open like the below image.
  4. disable the "Anonymous Authentication" and enable the "Window Authentication".






















paste in the web configuration

<system.web>
    <authentication mode="Windows">
</system.web>

What is Agile,advantage and disadvantages

Introduction:- It is a software development life cycle used for software development, that is characterized by the division of tasks in...