Pages

Sunday, April 12, 2020

Postman screen is blank or white or black

For Windows computers with certain GPU, Postman may display a blank/black window when opened, and elements in the app may not be rendering correctly or at all.

This issue may be related to a known issue where Postman doesn’t launch with certain GPU. A workaround for this issue involves disabling your GPU. Disabling GPU rendering for Postman generally allows the app to run successfully. To do so, you'll need to add a Windows environment variable: POSTMAN_DISABLE_GPU, with the value: true

Saturday, April 11, 2020

How to do migration from code to database in core web API

using EmployeeService.Model;
using Microsoft.EntityFrameworkCore;


namespace EmployeeService.Domain
{
    public class Connection:DbContext
    {

        public Connection(DbContextOptions opt):base(opt)
        {


        }

        public DbSet<Employee> Employee { get; set; }
    }
}

services.AddDbContext<Connection>(sp => sp.UseSqlServer("server=servername;database=database name;integrated security=true;USER ID= user;Password=password"));


https://www.entityframeworktutorial.net/efcore/entity-framework-core-migration.aspx

Wednesday, March 6, 2019

MVC Internal Architecture

MVC Internal Architecture or Request Pipe Line or Mvc Request Life Cycle


                               Route Table
                                   Routes
                                   Controller+Action
                                 RouteCollection
                                     |
                                    MapRoute---set default route

                                                                           ActionResult
  Browser----------------------------------------------MVC----controller+Action--view----MapRoute--RouteCollection--RouteConfig.cs
                                                       |
                                                       IIS

Tuesday, March 5, 2019

c# imp topics


                                   
             1. Architecture of C#
             2. compilation phase and execution phase of c#.
             3. Architecture of Assembly
             4. Architecture of CLR.
             5. Static Assembly and Shared Assembly.
             6. properties---****
             7. Indexer
             8. Reflection
             9. collection---*****
             10. Generics----*****
             11. Threading
             12. Exception Handling
             13. Garbage collection
             14. Extension Method
             15. conceopt of CTS(common type system/CLS(common language spectification).
             16. constructor chanining
             17. Delegate
                 1.) Asynchronous call)---Major Topics
                 2.) Anonymous call
                 3.) Lamda Exprssion.----Major Topics
                 4.) Multicast Delegate
            18. Interface and Abstract ----Major Topics   
     

           Major Keywords:.
       
        1. Dynamic
        2. Var
        3. out/ref
        4. volatile
        5. sealed class
        6. struct
        7. union
        8. new   
        9. virtual
        10. override

Token in Web API C#.Net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using WebApplication27.Models;

namespace WebApplication27.Controllers
{
    public class EmployeeController : Controller
    {
        // GET: Employee
        public ActionResult Index()
        {
            HttpClient obj = new HttpClient();
            obj.BaseAddress = new Uri("http://localhost:64430/api/");
            obj.DefaultRequestHeaders.Clear();
            obj.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            //Now Apply HttpVerbs
            IEnumerable<string> empList;
            HttpResponseMessage response = obj.GetAsync("employee").Result;
            empList = response.Content.ReadAsAsync<IEnumerable<string>>().Result;
            ViewBag.temp = empList;
            return View();
        }

        public ActionResult sendtoken()
        {


            using (var client = new HttpClient { BaseAddress = new Uri("http://localhost:64430/") })
            {
               //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var token = client.PostAsync("Token",
                    new FormUrlEncodedContent(new[]
                    {
                     new KeyValuePair<string,string>("grant_type","password"),
                     new KeyValuePair<string,string>("username","user"),
                     new KeyValuePair<string,string>("password","user")
                    })).Result.Content.ReadAsAsync<AuthenticationToken>().Result;

                client.DefaultRequestHeaders.Authorization =
                       new AuthenticationHeaderValue(token.token_type, token.access_token);

                Task<HttpResponseMessage> m = client.GetAsync("api/Account");
                Task<string> values = m.Result.Content.ReadAsStringAsync();
                ViewBag.temp = values.Result;
                return View();
            }
        }
    }
}

Saturday, February 9, 2019

Connection string in .Net

Connection string in .NET 3.5 (and above) config file
Do not use appsettings in web.config. Instead use the connectionStrings section in web.config.
<connectionStrings>
<add name="myConnectionString" connectionString="server=localhost;database=myDb;uid=myUser;password=myPass;" />
</connectionStrings>
To read the connection string into your code, use the ConfigurationManager class.
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
Connection string in .NET 2.0 config file

In the appSettings location, add a key named whatever you like to reference your connection string to.

<appSettings>
<add key="myConnectionString" value="server=localhost;database=myDb;uid=myUser;password=myPass;" />
</appSettings>

To read the connection string from code, use the ConfigurationSettings class.

string connStr = ConfigurationSettings.AppSettings("myConnectionString");

Sunday, December 16, 2018

Check if length of a number in a column is correct or not in Excel

Suppose there is a column having Aadhar Number which correct length is 5 .

Now excel have two column Pan Number and value will be false if length will be not equal to 5.

If Excel column name is A then put =LEN(A1)=5 for correct value result will be True else it will be false.

Aadhar Length
11111 =LEN(A1)=5
223 =LEN(A2)=5
567 =LEN(A3)=5
1111111 =LEN(A4)=5


Thursday, November 29, 2018

MVC link for quick learning

Action Method Parameters
  • We can organize the action methods for GET and POST requests separately.
  • We can easily create seperate action methods for each request types.
Request Type Attribute
  • [HttpGet]
  • [HttpPost]
Action method parameters
MVC framework provides 3 different action methods for Post Request, which are given below.
  1. Form Collection
  2. Formal Parameters
  3. Model Class Object 
1.
  1. using System.Web.Mvc;  
  2. namespace MVCActionMethodParameters.Controllers  
  3. {  
  4. public class HomeController : Controller  
  5. {  
  6. // GET: Home  
  7. [HttpGet]  
  8. public ActionResult Index()  
  9. {  
  10. return View();  
  11. }  
  12. [HttpPost]  
  13. public ActionResult Index(FormCollection frmobj) //FormCollection  
  14. {  
  15. string name = frmobj["userid"];  
  16. string password = frmobj["pwd"];  
  17. if (name == "Admin" && password == "123456")  
  18. {  
  19. Response.Write("<h2> Success </h2> Valid User");  
  20. }  
  21. else  
  22. Response.Write(" <h2> Failed </h2> Invalid User");  
  23. return View();  
  24. }  
  25. }  


  1. @{  
  2. ViewBag.Title = "Index";  
  3. }  
  4. <h1>Form Collection</h1>  
  5. <h2>Login </h2>  
  6. @using (Html.BeginForm())  
  7. {  
  8. <label>User Name</label>  
  9. <input type="text" class="form-control" id="userid" name="userid" />  
  10. <label>Password</label>  
  11. <input type="text" class="form-control" id="pwd" name="pwd" /> <br />  
  12. <input type="submit" class="btn btn-success" value="Submit" />  
  13. }  


2.

  1. using System.Web.Mvc;  
  2. namespace MVCActionMethodParameters.Controllers  
  3. {  
  4. public class LoginController : Controller  
  5. {  
  6. // GET: Login  
  7. [HttpGet]  
  8. public ActionResult Login()  
  9. {  
  10. return View();  
  11. }  
  12. [HttpPost]  
  13. public ActionResult Login(string userid, string pwd) //Formal Parameters  
  14. {  
  15. string username = userid;  
  16. string password = pwd;  
  17. if (username == "Admin" && password == "123456")  
  18. {  
  19. Response.Write("<h2> Success </h2> Valid User...");  
  20. }  
  21. else  
  22. Response.Write(" <h2> Failed </h2> Invalid User...");  
  23. return View();  
  24. }  
  25. }  
  26. }  

  1. @{  
  2. ViewBag.Title = "Login";  
  3. }  
  4. <h1>Formal Parameters</h1>  
  5. <hr />  
  6. <h2>Login</h2>  
  7. @using (Html.BeginForm())  
  8. {  
  9. <label>User Name</label>  
  10. <input type="text" class="form-control" id="userid" name="userid" />  
  11. <label>Password</label>  
  12. <input type="text" class="form-control" id="pwd" name="pwd" /> <br />  
  13. <input type="submit" class="btn btn-success" value="Submit" />  
  14. }  
3.
  1. namespace MVCActionMethodParameters.Models  
  2. {  
  3. public class Login  
  4. {  
  5. public string userid { getset; }  
  6. public string pwd { getset; }  
  7. }  
  1. namespace MVCActionMethodParameters.Models  
  2. {  
  3. public class Login  
  4. {  
  5. public string userid { getset; }  
  6. public string pwd { getset; }  
  7. }  

  1. <h1>Formal Parameters</h1>  
  2. <hr />  
  3. <h2>Login</h2>  
  4.    
  5. @using (Html.BeginForm())  
  6. {  
  7. <label>User Name</label>  
  8. <input type="text" class="form-control" id="userid" name="userid" />  
  9. <label>Password</label>  
  10. <input type="text" class="form-control" id="pwd" name="pwd" /> <br />  
  11. <input type="submit" class="btn btn-success" value="Submit" />