Saturday, August 24, 2019

c# 7 tuples enable

1. Enable tuple
 Install System.Tuples from NuGet Package Manager



2. c#7  new tuple return


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebApplication8.Models;

namespace WebApplication8.Controllers
{
    public class home_Controller : ApiController
    {
        //type1 
        [HttpGet]
        public (int st, string msg, List<Employee> emp_list) Get_Data([FromUri] Employee d)
        {
            int status = 1;
            string message = "Success";
            List<Employee> employee_list = new List<Employee>() { new Employee { Address = "Agra", Emp_Name = "Rinkesh", Mobile = 987998, Srno = 1 }
            ,new Employee { Address="Agra",Emp_Name="Manish",Mobile=987998,Srno=2 }
            ,new Employee { Address="Sandeep",Emp_Name="Mathura",Mobile=5555,Srno=3}
            };

            return (st: status, msg: message, emp_list: employee_list);
        }
       
        //type2 
        [HttpGet]
        public (int st, string msg, List<Employee> emp_list) Get_Data([FromUri] Employee d)
        {
            int status = 1;
            string message = "Success";
            List<Employee> employee_list = new List<Employee>() { new Employee { Address = "Agra", Emp_Name = "Rinkesh", Mobile = 987998, Srno = 1 }
            ,new Employee { Address="Agra",Emp_Name="Manish",Mobile=987998,Srno=2 }
            ,new Employee { Address="Sandeep",Emp_Name="Mathura",Mobile=5555,Srno=3}
            };

            return (status, message, employee_list);
        }
    }
}


Sunday, August 11, 2019

Access control allowed or cors allow

1. Access-Control-Allow-Origin
2.Access-Control-Allow-Headers
3.Access-Control-Allow-Methods
all allowed globaly (in web.config)

  <system.webServer>

    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Content-Type" />
        <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
      </customHeaders>
    </httpProtocol>


  </system.webServer>

Web.config connection


<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <connectionStrings>
    <!--<add name="cm_connection" connectionString="Data Source=AS-RIN;Initial Catalog=web_inc;User ID=sa;Password=mdts888" providerName="System.Data.SqlClient" />-->
    <add name="db_connection" connectionString="Data Source=OMG;Initial Catalog=test;User ID=sa;Password=mdts888" providerName="System.Data.SqlClient" />
    <!--<add name="cm_connection" connectionString="Data Source=sql5026.site4now.net;Initial Catalog=DB_A45CFD_rinkesh;User ID=DB_A45CFD_rinkesh_admin;Password=Rin@123456#" providerName="System.Data.SqlClient"/>-->
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

Saturday, August 10, 2019

Null Function in c# or null method in c#

        decimal? net_value(decimal? BASIC, decimal? WD, decimal? AB)
        {
            return BASIC - ((BASIC / WD) * AB);
        }

Thursday, August 8, 2019

HTTP Error 403.14 - Forbidden

The Web server is configured to not list the contents of this directory.


Solution Link 
1

2. 

3. Default Document must be Index.html or Default.aspx in IIS

Thursday, August 1, 2019

Core 2.2 db connection or Core 2.2 database connection

1. Update in root file appsettings.json like web.config

{
  "ConnectionStrings": {
    "DefaultConnection1": "Server=omg;Database=test;User Id=sa;Password=mdts888;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*"
}


2. Update in Startup.cs



    services.AddDbContext<db_context>(options =>
        options.UseSqlServer(
            Configuration.GetConnectionString("DefaultConnection1")));

    services.AddDbContext<db_context_>(options =>
                options.UseSqlServer(
                    Configuration.GetConnectionString("DefaultConnection1")));





3.

using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication6.Models;

namespace WebApplication6.Auth
{
    public class db_context : IdentityDbContext
    {
        public db_context(DbContextOptions<db_context> options)
            : base(options)
        {
        }
        public DbSet<WebApplication6.Models.customer> customer { get; set; }

    }

    public class db_context_ : DbContext
    {
        public db_context_(DbContextOptions<db_context> options)
            : base(options)
        {
        }
        public DbSet<WebApplication6.Models.customer> customer { get; set; }

    }
}



4. Installed Package




Linq Expression syntax for where condtion in linq

(Expression<Func<T, bool>> filter)