Thursday, August 22, 2019
Monday, July 1, 2019
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
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();
}
}
}
}
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");
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");
Subscribe to:
Posts (Atom)