Thursday, 3 March 2022

Redirecting Custom error in .Net Core

When we where working on .net mvc or aspx we  where configuring into the web.config file as default error page, like below.

 

<system.web>

    <customErrors mode="On">

      <error statusCode="404" redirect="/PageNotFound?" />

      <error statusCode="302" redirect="/unauthorised" />

    </customErrors>

</system.web>

 

But in .Net core we dont have web.config file to configure default error page.

In this case we need to configure it in startup.cs file.

 

Wednesday, 16 September 2020

Displaying the multiple rows data in single Row in SQL

 You have a scenario to show the multiple rows data into the  single rows like below.


In Above image you can see how the  multiple rows of above tables data is transformed into horzotally and make all the records into one row.
Just take the example of 1 data and taking it is making the horizontally as respect to the TIN wise.

where for TIN 1000 having the four different records but belongs to the one costumer only.

So first provide the row number to all the records like below.

SELECT SetId, AppCode, AppEventId, EventId,ValueData,phone,[Address], ROW_NUMBER()  OVER( PARTITION BY  AppCode  ORDER BY AppCode

) RowNumber

INTo #mineTable

FROM  dbo.valueDataCheck

In Above Code there we created a new temp table which will maintain the row number with other records and you can see in below line how we provide numbers to all the records

select * from #mineTable



Now main code how we will convert the row to horizontally like given in screen.

SELECT SetId, AppCode as TIN, AppEventId, EventId

  ,max(CASE WHEN RowNumber = 1 THEN ValueData END) AS val1

  ,max(CASE WHEN RowNumber = 2 THEN ValueData END) AS val2

  ,max(CASE WHEN RowNumber = 3 THEN ValueData END) AS val3

   --,max(CASE WHEN RowNumber = 4 THEN ValueData END) AS val4

   ,max(CASE WHEN RowNumber = 1 THEN phone END) AS phonenumber1

  ,max(CASE WHEN RowNumber = 2 THEN phone END) AS phonenumber2

  ,max(CASE WHEN RowNumber = 3 THEN phone END) AS phonenumber3

  -- ,max(CASE WHEN RowNumber = 4 THEN phone END) AS phonenumber4

   ,max(CASE WHEN RowNumber = 1 THEN [Address] END) AS add1

  ,max(CASE WHEN RowNumber = 2 THEN [Address] END) AS add2

  ,max(CASE WHEN RowNumber = 3 THEN [Address] END) AS add3

 -- ,max(CASE WHEN RowNumber = 4 THEN [Address] END) AS add4

 

   FROM #mineTable

   GROUP BY SetId,AppCode,AppEventId,EventId

  

   DROP TABLE #mineTable



It will help you to get the all the records horizontally . Dont forget to drop tables.


Deploying MVC in website in Big Rocks getting Security Error

 Once you deploy your website into big rocks you are getting the /Security Error.,


I faced the similar issue like below




Security Exception
Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request failed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[SecurityException: Request failed.]
   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(RuntimeAssembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) +165
   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) +100
   System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +272
   System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, RuntimeAssembly asm, SecurityAction action) +55
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +70
   System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +39
   System.Type.GetType(String typeName) +50
   System.CodeDom.Compiler.CompilerInfo.get_IsCodeDomProviderTypeValid() +10
   System.Web.Compilation.CompilationUtil.GetRecompilationHash(CompilationSection ps) +2090
   System.Web.Configuration.CompilationSection.get_RecompilationHash() +107
   System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDateInternal(Int64 cachedHash) +465
   System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDate(Int64 cachedHash) +51
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +132
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +521

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

It is happning even you are providing the trust level as full like below.

<system.Web>
...
    <trust level="Full"/>
...
</system.Web>
-----------------------------------------------

And fix for that is

You need to contact the  big rocks supporting team as your site need the  configuration of 4.7 , as it is build in MVC 5.0 + version so just check with them and they will give CAS access to full. Even if you do setting in PLSK it wont work they will provide it to you.