tag:blogger.com,1999:blog-89886620720080441072024-03-06T14:01:30.644+05:30DotNetterNikhilA Code Does it AllAnonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-8988662072008044107.post-78443703578811370572015-02-25T20:27:00.002+05:302015-03-21T14:34:12.322+05:30What is ViewBag, ViewData and TempData in MVC ?<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><br /></span>
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">In </span><a href="http://asp.net/" style="background-color: white; color: #1155cc; font-family: arial, sans-serif; font-size: 13px;" target="_blank">ASP.NET</a><span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"> MVC, Generally we have three options for passing data from Controller to View and in the request. </span><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><br /></span>
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">And that three options are :</span><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">1. ViewBag</span><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">2. ViewData and</span><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">3. TempData</span><br />
<br style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;" />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">ViewBag and ViewData are basically same and TempData have some additional responsibilities to perform.</span><br />
<b style="color: #222222; font-family: arial, sans-serif; font-size: 13px;"><u><br /></u></b>
<b style="color: #222222; font-family: arial, sans-serif; font-size: 13px;"><u><br /></u></b>
<b style="color: #222222; font-family: arial, sans-serif; font-size: 13px;"><u>ViewBag and ViewData</u></b><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">ViewBag and ViewData are generally used for same purpose. Both are used to transfer the data from controller to view and both of having a short life which lies only in current request. Short life means the value becomes null during the next request or any redirection occurs.</span><br />
<br style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;" />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><b>ViewBag </b>is a dynamic property which is able to set and get value dynamically.</span><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">ViewBag is basically a wrapper around the ViewData.</span><br />
<br style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;" />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><b>ViewData</b> is dictionary of an object which is accessible by string as a "key".</span><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">ViewData is a property of Controller that exposes an instance of ViewDataDictionary.</span><br />
<br style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;" />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><b><u><br /></u></b></span>
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><b><u>Difference between ViewBag and ViewData</u></b></span><br />
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: 1pt solid windowtext; padding: 0cm 5.4pt; text-align: center; width: 231.05pt;" valign="top" width="308"><b style="color: #222222; font-family: arial, sans-serif; font-size: 13px;"><u>ViewBag</u></b>
</td>
<td style="border-bottom-color: windowtext; border-bottom-width: 1pt; border-right-color: windowtext; border-right-width: 1pt; border-style: solid solid solid none; border-top-color: windowtext; border-top-width: 1pt; padding: 0cm 5.4pt; text-align: center; width: 231.05pt;" valign="top" width="308"><span style="color: #222222; font-family: arial, sans-serif;"><span style="font-size: 13px;"><b><u>ViewData</u></b></span></span>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 231.05pt;" valign="top" width="308"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt;">ViewBag is a dynamic property</span><o:p></o:p></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 231.05pt;" valign="top" width="308"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt;">ViewData is a dictionary of object which if
accessible using string as a "key".</span><o:p></o:p></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 231.05pt;" valign="top" width="308"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt;">ViewBag is a new dynamic feature of C# 4.0</span><o:p></o:p></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 231.05pt;" valign="top" width="308"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt;">ViewData is derived from ViewDataDictionary
class.</span><o:p></o:p></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 231.05pt;" valign="top" width="308"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt;">Works with .Net framework 4.0</span><o:p></o:p></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 231.05pt;" valign="top" width="308"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt;">Works with .Net framework 3.5</span><o:p></o:p></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 231.05pt;" valign="top" width="308"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt;">It doesn't require typecasting for complex
data type.</span><o:p></o:p></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 231.05pt;" valign="top" width="308"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt;">It requires typecasting for complex data type.</span><o:p></o:p></div>
</td>
</tr>
</tbody></table>
<br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><b><br /></b></span>
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><b>Example of ViewBag</b></span><br />
<br style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;" />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">At Controller</span><br />
<br />
<pre class="c-sharp" name="code">
Public ActionResult Index()
{
ViewBag.Author = "Nikhil";
Return View();
}
</pre>
<br style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;" />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">At View</span><br />
<pre class="c-sharp" name="code">
<label>@ViewBag.Author</label>
</pre>
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><b>Example of ViewData</b></span><br />
<br style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;" />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">At Controller</span><br />
<pre class="c-sharp" name="code">
Public ActionResult Index()
{
ViewData["Author"]= "Nikhil";
Return View();
}
</pre>
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">At View</span><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"></span><br />
<pre class="c-sharp" name="code">
<label>@ViewData["Author"] </label>
</pre>
<br />
<br style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;" />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><b>TempData</b></span><br />
<br style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;" />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">TempData is also a dictionary which is derived from TempDataDictionary class.</span><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">TempData is stored data just like a session for limited period of time.</span><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">TempData holds the data for the time of HTTPRequest means it holds the data between two consecutive request.</span><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">So, the TempData is useful for transferring the data from one Controller to another Controller and one Action to another Actions.</span><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">Initially the TempData uses the session variables. It helps to maintain the data between controllers and actions. It requires the typecasting for such complex data types.</span><br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">TempData is generally used to save one time message. but you can keep the value after the completion of request by using <b> keep() </b> method.</span><br />
<br style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;" />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><b>Example of TempData</b></span><br />
<br style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;" />
<pre class="c-sharp" name="code">
Public ActionResult Index()
{
var dbModelData = new Author (){ Name = "Nikhil", UserName = "DotNetter"};
TempData["objModel"] = dbModelData;
Return RedirectToAction("Login");
}
Public ActionResult Index()
{
var modelDetails = TempData["objModel"];
Return View(modelDetails);
}
</pre>
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><b>At the End :</b></span><br />
<br style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;" />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">In </span><a href="http://asp.net/" style="background-color: white; color: #1155cc; font-family: arial, sans-serif; font-size: 13px;" target="_blank">ASP.NET</a><span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"> MVC, we have three options ViewBag, ViewData and TempData for sending the data between Controllers and Views and in next request. Basically ViewBag and ViewData are same and used for sending data from Controller to View and TempData is used during current and subsequent request that means you can pass data between Controllers and Actions with the help of TempData.</span></div>Anonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.com0tag:blogger.com,1999:blog-8988662072008044107.post-60051646790522193542014-12-23T09:30:00.000+05:302014-12-23T09:30:00.412+05:30Check whether an email address is valid or not ?<div dir="ltr" style="text-align: left;" trbidi="on">
Some times, we require some common function like Get Random GUID, or some validations like passowrd is strong or not.<br />
<br />
So, here i show you the validation of Email address field that checks whether the entered email address is valid or not ?<br />
<br />
<br />
I have created a function "CheckEmail", which accepts the EmailAddress imput as an parameter.<br />
You have to pass your input Emailaddress value to this function and this function will return you a boolean (true/false), if the entered email address is valid then it will return true until false.<br />
<br />
<pre name="code" class="csharp">
//<param name="emailAddress">Your Email Address</param><br />
public static bool CheckEmail(string emailAddress)<br />
{<br />
bool isValid = true;<br />
if (string.IsNullOrWhiteSpace(emailAddress.Trim()))<br />
{<br />
isValid = false;<br />
}<br />
else<br />
{<br />
RegexStringValidator re = new RegexStringValidator(@"^[a-zA-Z0-9][-\w\.]*@([a-zA-Z0-9][\w\-]*\.)+[a-zA-Z]{2,3}$");<br />
try<br />
{<br />
re.Validate(emailAddress);<br />
}<br />
catch<br />
{<br />
isValid = false;<br />
}<br />
}<br />
return isValid;<br />
}<br />
<br />
</pre>
For RegexStringValidator class, you have to add this namespace <pre name="code" class="csharp">using System.Configuration</pre></div>
Anonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.com1tag:blogger.com,1999:blog-8988662072008044107.post-33463391368076140102014-12-22T05:30:00.000+05:302015-03-21T14:31:17.865+05:30Difference between ApiController and Controller in ASP.NET MVC<div dir="ltr" style="text-align: left;" trbidi="on">
In Today's generation all the peoples are very smart. They are using mobiles, tablets etc. device in those days rather than browser and these device have unlimited apps for make a life smooth. At the end, we all are moving from the web world towards the app world.<br />
<br />
<br />
So, why not we will develop a worth program which will be helpful in both web and app world.<br />
So, For that i suggest go through ApiControllers.<br />
<br />
<h3 style="text-align: left;">
<u><b>Difference :</b></u></h3>
1) You can use controller to render your normal views only.<br />
but using the ApiController action only returns the data which is serialized and sent to client.<br />
So, that you can use it any Html based application.<br />
<br />
2) You can self hosting using ApiController but not from MVC Controllers.<br />
<br />
3) If you are aware with ASP.NET MVC then you are already knows about the controllers.<br />
And the APIControllers are same as MVC controllers, but it inherits the ApiController class instead of the Controller class.<br />
<br />
4) APIControllers is a lightweight architecture excepting the web Apps. <br />
<br />
5) MVC Controller shows the URL Samples matching the default route pattern"{controller}/{action}/{id}". and the ApiController shows "api/{controller}/{id}".<br />
<br />
6) Web API Supports the self hosting, content negotiation where the MVC doesn't support it.<br />
<br />
7) <b>Use Controller when</b> - If you're writing an HTML based web/internet application (with the occasional AJAX call returning json here and there).<br />
<b>Use ApiControllers When</b> - If you want to provide a data driven/REST-ful interface to a system.<br />
<br />
8) For Example, <br />
<pre name="code" class="csharp" style="overflow:scroll;">
//In ASP.NET MVC
public class PostsController : Controller
{
// GET: /Tweets/
[HttpGet]
public ActionResult Index() {
return Json(Facebook.GetAllPosts(), JsonRequestBehavior.AllowGet);
}
}
//ASP.NET Web API<br />
public class TweetsController : ApiController
{
// GET: /Api/Tweets/
public List<Posts> GetAllPosts() {
return Facebook.GetAllPosts();
}
}
</pre>
<i>So, You have to use the API which is compatible with the browsers and all the modern devices apps.<br />Actually, the Web API is a open source platform for building a REST-ful services over the .Net Framework. </i><br />
<br />
<br />
Now, I hope you have got when to use Web API over MVC and how it works. <br />
Please keep commenting every author needs motivation.</div>
Anonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.com0tag:blogger.com,1999:blog-8988662072008044107.post-88703217403215725522014-12-19T19:07:00.000+05:302015-03-21T14:32:07.450+05:30MVC Interview Questions and Answers<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="clear: both; text-align: center;">
<b><span style="color: #0b5394;">Model View Controller</span></b></h2>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC7lRxPhbD4a2oFwHqSXqe0zT9CXw089JLOU4mKLl571TaQhuSJOVZmTn5zggGpS6ZyHHimh95BXDLr9BN8c232IJFnC-3e4Wl2BvhqtB9RQsYuXCSEBr7ZzpTp4TL2zHUB1ITcrac89U/s1600/mvc.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC7lRxPhbD4a2oFwHqSXqe0zT9CXw089JLOU4mKLl571TaQhuSJOVZmTn5zggGpS6ZyHHimh95BXDLr9BN8c232IJFnC-3e4Wl2BvhqtB9RQsYuXCSEBr7ZzpTp4TL2zHUB1ITcrac89U/s1600/mvc.png" height="200" width="193" /></a></div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<br /></div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
By reading these MVC interview question it does not mean you will go and clear MVC interviews. The whole purpose of this Post is to quickly brush up your MVC knowledge before you for the MVC interviews.</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Before Going for Question Answers, i will give you a little bit of introduction about MVC.</div>
<h3 style="background-color: white; border-top-color: rgb(224, 224, 224); border-top-style: solid; border-width: 5px 0px 0px; clear: both; font-family: 'Helvetica Neue', Helvetica, Verdana, 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 20px 0px 0px; outline: 0px; padding: 10px 0px 0px; vertical-align: baseline;">
What is MVC?</h3>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
MVC is a framework pattern that splits an application’s implementation logic into three component roles: models, views, and controllers.</div>
<ul style="background-color: white; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; list-style: square; margin: 12px 0px; outline: 0px; padding: 0px 0px 0px 20px; vertical-align: baseline;">
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">Model</strong>: The business entity on which the overall application operates. Many applications use a persistent storage mechanism (such as a database) to store data. MVC does not specifically mention the data access layer because it is understood to be encapsulated by the Model.</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">View</strong>: The user interface that renders the Model into a form of interaction.</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">Controller</strong>: Handles a request from a View and updates the Model that results in a change of the Model’s state.To implement MVC in .NET, we need mainly three classes (<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">View</code>, <code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Controller </code>and the <code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Model</code>).<br /><h3 style="border-top-color: rgb(224, 224, 224); border-top-style: solid; border-width: 5px 0px 0px; clear: both; color: black; font-family: 'Helvetica Neue', Helvetica, Verdana, 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 20px 0px 0px; outline: 0px; padding: 10px 0px 0px; vertical-align: baseline;">
Explain MVC Architecture?</h3>
</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><img alt="" border="0" height="223" hspace="0" src="https://i0.wp.com/www.codeproject.com/KB/aspnet/639717/image001.jpg" style="height: auto; max-width: 100%;" width="567" /></li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> The architecture is self explanatory. The browser (as usual) sends a request to IIS, IIS searches for the route defined in MVC application and passes the request to the controller as per route, the controller communicates with the model and passes the populated model (entity) to View (front end), Views are populated with model properties, and are rendered on the browser, passing the response to browser through IIS via controllers which invoked the particular View.</li>
</ul>
<h3 style="background-color: white; border-top-color: rgb(224, 224, 224); border-top-style: solid; border-width: 5px 0px 0px; clear: both; font-family: 'Helvetica Neue', Helvetica, Verdana, 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 20px 0px 0px; outline: 0px; padding: 10px 0px 0px; vertical-align: baseline;">
Features of MVC 2.0</h3>
<ul style="background-color: white; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; list-style: square; margin: 12px 0px; outline: 0px; padding: 0px 0px 0px 20px; vertical-align: baseline;">
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Introduction of UI helpers with automatic scaffolding with customizable templates</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Attribute-based model validation on both client and server</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Strongly typed HTML helpers</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Improved Visual Studio tooling</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">There were also lots of API enhancements and “pro” features, based on feedback from developers building a variety of applications on ASP.NET MVC 1.0, such as:<ul style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; list-style: square; margin: 0px; outline: 0px; padding: 0px 0px 0px 20px; vertical-align: baseline;">
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Support for partitioning large applications into areas</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Asynchronous controllers support</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Support for rendering subsections of a page/site using <code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Html.RenderAction</code></li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Lots of new helper functions, utilities, and API enhancements</li>
</ul>
</li>
</ul>
<h3 style="background-color: white; border-top-color: rgb(224, 224, 224); border-top-style: solid; border-width: 5px 0px 0px; clear: both; font-family: 'Helvetica Neue', Helvetica, Verdana, 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 20px 0px 0px; outline: 0px; padding: 10px 0px 0px; vertical-align: baseline;">
Features of MVC 3.0</h3>
<ul style="background-color: white; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; list-style: square; margin: 12px 0px; outline: 0px; padding: 0px 0px 0px 20px; vertical-align: baseline;">
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">The Razor view engine</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Support for .NET 4 Data Annotations</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Improved model validation</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Greater control and flexibility with support for dependency resolution and global action filters</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Better JavaScript support with unobtrusive JavaScript, jQuery Validation, and JSON binding</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Use of NuGet to deliver software and manage dependencies throughout the platform</li>
</ul>
<h3 style="background-color: white; border-top-color: rgb(224, 224, 224); border-top-style: solid; border-width: 5px 0px 0px; clear: both; font-family: 'Helvetica Neue', Helvetica, Verdana, 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 20px 0px 0px; outline: 0px; padding: 10px 0px 0px; vertical-align: baseline;">
Features of MVC 4.0</h3>
<ul style="background-color: white; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; list-style: square; margin: 12px 0px; outline: 0px; padding: 0px 0px 0px 20px; vertical-align: baseline;">
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">ASP.NET Web API</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Enhancements to default project templates</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Mobile project template using jQuery Mobile</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Display Modes</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Task support for Asynchronous Controllers</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Bundling and minification</li>
</ul>
<h3 style="background-color: white; border-top-color: rgb(224, 224, 224); border-top-style: solid; border-width: 5px 0px 0px; clear: both; font-family: 'Helvetica Neue', Helvetica, Verdana, 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 20px 0px 0px; outline: 0px; padding: 10px 0px 0px; vertical-align: baseline;">
Advantages of MVC</h3>
<ol style="background-color: white; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; list-style-image: initial; list-style-position: initial; margin: 12px 0px; outline: 0px; padding: 0px 0px 0px 20px; vertical-align: baseline;">
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Provides a clean separation of concerns between UI (Presentation layer), model (Transfer objects/Domain Objects/Entities) and Business Logic (Controller)</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Easy to UNIT Test</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Improved reusability of views/model. One can have multiple views which can point to the same model and vice versa</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Improved structuring of the code</li>
</ol>
<h3 style="background-color: white; border-top-color: rgb(224, 224, 224); border-top-style: solid; border-width: 5px 0px 0px; clear: both; font-family: 'Helvetica Neue', Helvetica, Verdana, 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 20px 0px 0px; outline: 0px; padding: 10px 0px 0px; vertical-align: baseline;">
Explain Routing in MVC</h3>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
A route is a URL pattern that is mapped to a handler. The handler can be a physical file, such as an <em style="border: 0px; font-family: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">.aspx</em> file in a Web Forms application. Routing module is responsible for mapping incoming browser requests to particular MVC controller actions.</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Routing within the ASP.NET MVC framework serves two main purposes:</div>
<ul style="background-color: white; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; list-style: square; margin: 12px 0px; outline: 0px; padding: 0px 0px 0px 20px; vertical-align: baseline;">
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">It matches incoming requests that would not otherwise match a file on the file system and maps the requests to a controller action.</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">It constructs outgoing URLs that correspond to controller actions.</li>
</ul>
<h3 style="background-color: white; border-top-color: rgb(224, 224, 224); border-top-style: solid; border-width: 5px 0px 0px; clear: both; font-family: 'Helvetica Neue', Helvetica, Verdana, 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 20px 0px 0px; outline: 0px; padding: 10px 0px 0px; vertical-align: baseline;">
Now Ready for Question – Answers:</h3>
<blockquote style="background-color: #e0e0e0; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; margin: 20px; opacity: 0.8; outline: 0px; padding: 10px 15px; quotes: ''; vertical-align: baseline;">
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">1. What are the 3 main components of an ASP.NET MVC application?</strong><br />
1. M – Model<br />
2. V – View<br />
3. C – Controller</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">2. In which assembly is the MVC framework defined?</strong><br />
System.Web.Mvc</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">3. Is it possible to combine ASP.NET webforms and ASP.MVC and develop a single web application?</strong><br />
Yes, it is possible to combine ASP.NET webforms and ASP.MVC and develop a single web application.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">4. What does Model, View and Controller represent in an MVC application?</strong><br />
Model: Model represents the application data domain. In short the applications business logic is contained with in the model.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
View: Views represent the user interface, with which the end users interact. In short the all the user interface logic is contained with in the UI.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Controller: Controller is the component that responds to user actions. Based on the user actions, the respective controller, work with the model, and selects a view to render that displays the user interface. The user input logic is contained with in the controller.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">5. What is the greatest advantage of using asp.net mvc over asp.net webforms?</strong><br />
It is difficult to unit test UI with webforms, where views in mvc can be very easily unit tested.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">6. Which approach provides better support for test driven development – ASP.NET MVC or ASP.NET Webforms?</strong><br />
ASP.NET MVC</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">7. What are the advantages of ASP.NET MVC?</strong><br />
1. Extensive support for TDD. With asp.net MVC, views can also be very easily unit tested.<br />
2. Complex applications can be easily managed<br />
3. Seperation of concerns. Different aspects of the application can be divided into Model, View and Controller.<br />
4. ASP.NET MVC views are light weight, as they donot use viewstate.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">8. Is it possible to unit test an MVC application without running the controllers in an ASP.NET process?</strong><br />
Yes, all the features in an asp.net MVC application are interface based and hence mocking is much easier. So, we don’t have to run the controllers in an ASP.NET process for unit testing.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">9.Is it possible to share a view across multiple controllers?</strong><br />
Yes, put the view into the shared folder. This will automatically make the view available across multiple controllers.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">10. What is the role of a controller in an MVC application?</strong><br />
The controller responds to user interactions, with the application, by selecting the action method to execute and alse selecting the view to render.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">11.Where are the routing rules defined in an asp.net MVC application?</strong><br />
In Application_Start event in Global.asax</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">12. Name a few different return types of a controller action method?</strong><br />
The following are just a few return types of a controller action method. In general an action method can return an instance of a any class that derives from ActionResult class.<br />
1. ViewResult<br />
2. JavaScriptResult<br />
3. RedirectResult<br />
4. ContentResult<br />
5. JsonResult</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">13.What is the significance of NonActionAttribute?</strong><br />
In general, all public methods of a controller class are treated as action methods. If you want prevent this default behaviour, just decorate the public method with NonActionAttribute.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">14. What is the significance of ASP.NET routing?</strong><br />
ASP.NET MVC uses ASP.NET routing, to map incoming browser requests to controller action methods. ASP.NET Routing makes use of route table. Route table is created when your web application first starts. The route table is present in the Global.asax file.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">15. What are the 3 segments of the default route, that is present in an ASP.NET MVC application?</strong><br />
1st Segment – Controller Name<br />
2nd Segment – Action Method Name<br />
3rd Segment – Parameter that is passed to the action method</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">Example: <a href="http://dotnetternikhil.com/Nikhil/Home/1" rel="nofollow" style="border: 0px; color: #835504; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;">http://dotnetternikhil.com/Nikhil/Home/1</a></strong><br />
Controller Name = Nikhil<br />
Action Method Name = Home<br />
Parameter Id = 1</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">16. ASP.NET MVC application, makes use of settings at 2 places for routing to work correctly. What are these 2 places?</strong><br />
1. Web.Config File : ASP.NET routing has to be enabled here.<br />
2. Global.asax File : The Route table is created in the application Start event handler, of the Global.asax file.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">17.What is the adavantage of using ASP.NET routing?</strong><br />
In an ASP.NET web application that does not make use of routing, an incoming browser request should map to a physical file. If the file does not exist, we get page not found error.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
An ASP.NET web application that does make use of routing, makes use of URLs that do not have to map to specific files in a Web site. Because the URL does not have to map to a file, you can use URLs that are descriptive of the user’s action and therefore are more easily understood by users.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">18. What are the 3 things that are needed to specify a route?</strong><br />
1. URL Pattern – You can include placeholders in a URL pattern so that variable data can be passed to the request handler without requiring a query string.<br />
2. Handler – The handler can be a physical file such as an .aspx file or a controller class.<br />
3. Name for the Route – Name is optional.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">19. Is the following route definition a valid route definition?</strong><br />
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">{controller}{action}/{id}</strong><br />
No, the above definition is not a valid route definition, because there is no literal value or delimiter between the placeholders. Therefore, routing cannot determine where to separate the value for the controller placeholder from the value for the action placeholder.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">20. What is the use of the following default route?</strong><br />
{resource}.axd/{*pathInfo}<br />
This route definition, prevent requests for the Web resource files such as WebResource.axd or ScriptResource.axd from being passed to a controller.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">21. What is the difference between adding routes, to a webforms application and to an mvc application?</strong><br />
To add routes to a webforms application, we use MapPageRoute() method of the RouteCollection class, where as to add routes to an MVC application we use MapRoute() method.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">22. How do you handle variable number of segments in a route definition?</strong><br />
Use a route with a catch-all parameter. An example is shown below. * is referred to as catch-all parameter.<br />
controller/{action}/{*parametervalues}</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">23. What are the 2 ways of adding constraints to a route?</strong><br />
1. Use regular expressions<br />
2. Use an object that implements IRouteConstraint interface</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">24. Give 2 examples for scenarios when routing is not applied?</strong><br />
1. A Physical File is Found that Matches the URL Pattern – This default behaviour can be overriden by setting the RouteExistingFiles property of the RouteCollection object to true.<br />
2. Routing Is Explicitly Disabled for a URL Pattern – Use the RouteCollection.Ignore() method to prevent routing from handling certain requests.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">25. What are the 2 popular asp.net mvc view engines?</strong></div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
1. Razor<br />
2. .aspx</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">26. What symbol would you use to denote, the start of a code block in razor views?</strong><br />
@</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">27. What symbol would you use to denote, the start of a code block in aspx views?</strong><br />
<%= %></div>
</blockquote>
</div>
Anonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.com0tag:blogger.com,1999:blog-8988662072008044107.post-37542616287558417592014-12-19T19:03:00.001+05:302015-03-21T14:35:19.058+05:30Facebook Integration in MVC 3.0 (.Net)<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXfMe8uccbZ1xqi-1dy5Fmp-7nexFlgQvK3SvXuTP1wahA4T8ha2b57nJY4vvpVJGqh38Im8IJlzqlWF4dmSvodbnn0qAOPBSAFfar5IRZRGKV06a4Z8HNhEjD7kRDMHn9rCjUtNEfLb4/s1600/index+(1).jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXfMe8uccbZ1xqi-1dy5Fmp-7nexFlgQvK3SvXuTP1wahA4T8ha2b57nJY4vvpVJGqh38Im8IJlzqlWF4dmSvodbnn0qAOPBSAFfar5IRZRGKV06a4Z8HNhEjD7kRDMHn9rCjUtNEfLb4/s1600/index+(1).jpg" height="155" width="200" /></a></div>
<br />
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Now, Time for Facebook Integration in .Net MVC 3.0.</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Step 1 : Download Library package reference of Facebook from NuGet Package Installer.</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Step 2 : import namespace of facebook as like, </div>
<blockquote style="background-color: #e0e0e0; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; margin: 20px; opacity: 0.8; outline: 0px; padding: 10px 15px; quotes: ''; vertical-align: baseline;">
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
using facebook;</div>
</blockquote>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Step 3 : This uri method handles Our call back method that will returns from facebook site after Completed Login screen. </div>
<blockquote style="background-color: #e0e0e0; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; margin: 20px; opacity: 0.8; outline: 0px; padding: 10px 15px; quotes: ''; vertical-align: baseline;">
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
private System.Uri RedirectUri<br />
{<br />
get<br />
{<br />
var uribuilder = new UriBuilder(Request.Url);<br />
uribuilder.Query = null;<br />
uribuilder.Fragment = null;<br />
uribuilder.Path = Url.Action(“FacebookCallBack”);<br />
return uribuilder.Uri;<br />
}<br />
}</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
public ActionResult Facebook()<br />
{<br />
var fb = new FacebookClient();<br />
var loginurl = fb.GetLoginUrl(new<br />
{<br />
client_id = “463931757029793”,<br />
client_secret = “add31b78281d6ffccc7d1b887f77d9d4″,<br />
redirect_uri = RedirectUri.AbsoluteUri,<br />
responce_type = “code”,<br />
scope = “email,publish_stream,user_hometown,user_website”<br />
});<br />
return Redirect(loginurl.AbsoluteUri);<br />
}</div>
</blockquote>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Step 4 : Now, get the Details from facebook Client..</div>
<blockquote style="background-color: #e0e0e0; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; margin: 20px; opacity: 0.8; outline: 0px; padding: 10px 15px; quotes: ''; vertical-align: baseline;">
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
public ActionResult FacebookCallBack(string code)<br />
{<br />
var fb = new FacebookClient();<br />
dynamic result = fb.Post(“oauth/access_token”, new<br />
{<br />
client_id = “463931757029793”,<br />
client_secret = “add31b78281d6ffccc7d1b887f77d9d4″,<br />
redirect_uri = RedirectUri.AbsoluteUri,<br />
code = code<br />
});</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
var accessTocken = result[0];<br />
Session[“AccessTocken”] = accessTocken;<br />
fb.AccessToken = accessTocken;</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
dynamic me = fb.Get(“me?fields=first_name,last_name,id,email”);</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
String email = me[3];</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
return RedirectToAction(“LoginView”);<br />
}</div>
</blockquote>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Now, Finally this is Done…!!!</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Yippee. Always Enjoy coding !!</div>
</div>
Anonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.com0tag:blogger.com,1999:blog-8988662072008044107.post-14488063150893130242014-12-19T19:00:00.000+05:302015-03-21T14:36:02.439+05:30Twilio API Integration for sending SMS and List of Sent SMS<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGTDk_LeQZ3euAbgPKjca2qKAXar5Z6WXEVMhnoFDjvytLCHu6pWWf34W-mVqcUU9poVR3mka905rXrU6XnIjo2HXH4q6PJSHrpEQczW1JsjSFj5BUdetj3oVIuKJl3nEU6iuBp9bO9hU/s1600/images-1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGTDk_LeQZ3euAbgPKjca2qKAXar5Z6WXEVMhnoFDjvytLCHu6pWWf34W-mVqcUU9poVR3mka905rXrU6XnIjo2HXH4q6PJSHrpEQczW1JsjSFj5BUdetj3oVIuKJl3nEU6iuBp9bO9hU/s1600/images-1.jpg" height="149" width="200" /></a></div>
<br />
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Now, you can send SMS using Twilio API easily by just following the few Steps:</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;"><span style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: underline; vertical-align: baseline;">Steps:</span></strong></div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
1. Login in to the <a href="http://www.twilio.com/" rel="nofollow" style="border: 0px; color: #835504; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;">http://www.twilio.com</a> and if you are not user then sign in.<br />
2. Now Open Visual Studio and start your project and download twilio and twilioML library from NuGet package installer.<br />
3. After Login in twilio it will gives you a “ACCOUNT SID” and “AUTH TOKEN” and also “TELEPHONE NUMBER”. Save this credentials and apply in our project as..</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
//you have to add namespace for twilio as like,<br />
using twilio.com;</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
//and Now apply that Credentials in to our project..</div>
<blockquote style="background-color: #e0e0e0; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; margin: 20px; opacity: 0.8; outline: 0px; padding: 10px 15px; quotes: ''; vertical-align: baseline;">
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">String AccountSid</code> <code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">= </code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"</code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</code> // Account ID..<br />
<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">String </code>AuthToken</code> <code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">= </code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"</code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">; // Authentication Tocken.. </code><br />
<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">String </code>TelephoneNo</code> <code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">= </code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">'NNNNNNNNNN'</code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">; // Telephone No from the message will sent.</code></div>
</blockquote>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Now, Create Instance of Twilio Rest Client..</div>
<blockquote style="background-color: #e0e0e0; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; margin: 20px; opacity: 0.8; outline: 0px; padding: 10px 15px; quotes: ''; vertical-align: baseline;">
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">var client</code> <code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">= </code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">new</code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">TwilioRestClient(</code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">$AccountSid</code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">, </code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">$AuthToken</code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">);</code></div>
</blockquote>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Now, Call the Method SendSmsMessage(“Sender No with country Code”, “Receiver No with Country Code”, “Message Body…”) for sending SMS. as like,</div>
<blockquote style="background-color: #e0e0e0; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; margin: 20px; opacity: 0.8; outline: 0px; padding: 10px 15px; quotes: ''; vertical-align: baseline;">
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">cvar sendsms = client.sendSmsMessage(from,to,msg);</code><code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"></code></div>
</blockquote>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Done…. Yuppp…<br />
Your Project is Working…..</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
* Note:<br />
You can also set Validation on that like “Message length should not be greater than 160 Characters.. etc.”</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<br /></div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Now, You can easily manage sent message list..<br />
as below,</div>
<pre class="csharp" name="code">
public SMSMessage getMessageList(String to, String from)
{
String AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Account ID..
String AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"; // Authentication Tocken..
var client = new TwilioRestClient(AccountSid,AuthToken);
SmsMessageResult msgs = postMaster.ListSmsMessages();
List<SMSMessage> msg = msgs.SMSMessages;
foreach (var smsmsg in msgs.SMSMessages)
{
if (smsmsg.Status == “received” && smsmsg.From == from && smsmsg.To == to)
{
return smsmsg;
}
}
return null;
}
</pre>
</div>Anonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.com3tag:blogger.com,1999:blog-8988662072008044107.post-693377600472959262014-12-19T18:53:00.004+05:302015-03-21T14:30:04.392+05:30Send Data from Java Script to Controller in .NET MVC<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4P-bdp_7IHsWt7NjQDeRPG-fGe1Px-m7yNx2bSBUxgYoY2-Q-vE66BtOD02qWLshZIHSMWhO3oSBdiUtXJ4GhrY31aebcQbQlojIL9Lcxf44Oid9zh7sckyUY7dvS8F97-e2_f01nHnE/s1600/timthumb.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4P-bdp_7IHsWt7NjQDeRPG-fGe1Px-m7yNx2bSBUxgYoY2-Q-vE66BtOD02qWLshZIHSMWhO3oSBdiUtXJ4GhrY31aebcQbQlojIL9Lcxf44Oid9zh7sckyUY7dvS8F97-e2_f01nHnE/s1600/timthumb.png" /></a></div>
<br /></div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
Now, When you are working on some Java script APIs or like for some other purpose you have to send java script data to Controller for storing that value in Database.</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
So, for that you have use the $.Ajax() for pass this java script data to controller.</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
and at Controller side, you can get that data easily…</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">As Like,</strong><br />
<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><br /> </code></div>
<blockquote style="background-color: #e0e0e0; border: 0px; font-family: inherit; font-size: 13px; font-style: inherit; font-weight: inherit; margin: 20px; opacity: 0.8; outline: 0px; padding: 10px 15px; quotes: '', ''; vertical-align: baseline;">
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
var uname = 'Nikhil Prajapati';</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
$.ajax({<br />
url: "/Main/getRequestID", // This is path of your Controller with Action Result.<br />
dataType: "json", // Data Type for sending the data<br />
data: { // Data that will be passed to Controller<br />
'my_name': uname, // assign data like key-value pair<br />
// 'my_name' like fields in quote is same with parameter in action Result<br />
},<br />
type: "POST", // Type of Request</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
contentType: "application/json; charset=utf-8", //Optional to specify Content Type.</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
success: function (data) { // This function is executed when this request is succeed.<br />
alert(data);<br />
},<br />
error: function (data) {<br />
alert("Error"); // This function is executed when error occurred.<br />
}</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
});</div>
</blockquote>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"></code><br />
Now, At <strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">Controller Side</strong>,</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
in <strong style="border: 0px; color: black; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-shadow: rgb(204, 255, 255) 2px 2px 2px; vertical-align: baseline;">MainController.cs</strong></div>
<blockquote style="background-color: #e0e0e0; border: 0px; color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 12px; margin: 20px; opacity: 0.8; outline: 0px; padding: 10px 15px; quotes: ''; vertical-align: baseline;">
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
public ActionResult getRequestID(String my_name)<br />
{<br />
MYDBModel myTable = new Models.MYDBModel();<br />
myTable.FBUserName = my_name;<br />
db.MYDBModel.Add(myTable);<br />
db.SaveChanges(); // db object of our DbContext.cs.<br />
//return RedirectToAction(“Index”); // After that you can redirect to some pages…<br />
return Json(true, JsonRequestBehavior.AllowGet); // Or you can get that data back after inserting into database.. This json displays all the details to our view as well.<br />
}</div>
</blockquote>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"></code></div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 12px; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;">
So, Yupp, you can pass the java script data easily to Controller..</div>
</div>
Anonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.com0tag:blogger.com,1999:blog-8988662072008044107.post-83360360364041347732014-12-18T09:31:00.005+05:302014-12-19T18:56:11.566+05:30Password Encryption and Decryption in ASP.NET<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: center;">
<a href="http://dotnetternikhil.files.wordpress.com/2013/07/secure_passwords.jpg"><img alt="secure_passwords" class="size-medium wp-image-50 aligncenter" src="http://dotnetternikhil.files.wordpress.com/2013/07/secure_passwords.jpg?w=300" height="266" width="300" /></a> </div>
<b>
1. This Method illustrates the Password Encryption...</b>
<br />
<blockquote>
<span style="color: #3d85c6;">public static string Encrypt(string originalString)<br />
{<br />
if (originalString == null)<br />
{<br />
return originalString = “”;<br />
}<br />
if (String.IsNullOrEmpty(originalString))<br />
{<br />
throw new ArgumentNullException<br />
(“The string which needs to be encrypted can not be null.”);<br />
}<br />
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();<br />
MemoryStream memoryStream = new MemoryStream();<br />
CryptoStream cryptoStream = new CryptoStream(memoryStream,<br />
cryptoProvider.CreateEncryptor(bytes, bytes), <span class="skimlinks-unlinked">CryptoStreamMode.Write</span>);<br />
StreamWriter writer = new StreamWriter(cryptoStream);<br />
<span class="skimlinks-unlinked">writer.Write(originalString</span>);<br />
<span class="skimlinks-unlinked">writer.Flush</span>();<br />
cryptoStream.FlushFinalBlock();<br />
<span class="skimlinks-unlinked">writer.Flush</span>();<br />
return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);<br />
} </span></blockquote>
Now, You can call this mehod as ClassName.Encrypt("Your Password");<br />
<br />
<strong>2.</strong> This<strong> Method illustrates the<strong> Password Decryption...</strong></strong>
<br />
<blockquote>
<span style="background-color: white; color: #3d85c6;">public static string Decrypt(string cryptedString)<br />
{<br />
if (String.IsNullOrEmpty(cryptedString))<br />
{<br />
throw new ArgumentNullException<br />
(“The string which needs to be decrypted can not be null.”);<br />
}<br />
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();<br />
MemoryStream memoryStream = new MemoryStream<br />
(Convert.FromBase64String(cryptedString));<br />
CryptoStream cryptoStream = new CryptoStream(memoryStream,<br />
cryptoProvider.CreateDecryptor(bytes, bytes), <span class="skimlinks-unlinked">CryptoStreamMode.Read</span>);<br />
StreamReader reader = new StreamReader(cryptoStream);<br />
return reader.ReadToEnd();<br />
} </span></blockquote>
<br />
Now, You can call this mehod as ClassName.Decrypt("Your Encrypted Password")
<br />
<br />
<i><span style="text-decoration: underline;"><strong>Note :</strong></span><strong> </strong></i> <i>for that you have to add namespace of System.Security.Cryptography as like, </i><br />
<span style="color: #0b5394;"><i><b> using System.Security.Cryptography;
</b></i></span><br />
<span style="color: #0b5394;"><i><b><br /></b></i></span>
<span style="color: #0b5394;"><i><b><br /></b></i></span></div>
Anonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.com0tag:blogger.com,1999:blog-8988662072008044107.post-69254453169272008972014-08-02T11:17:00.000+05:302014-12-20T17:35:04.508+05:30Youtube Search and play Video in Windows Phone<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="http://dotnetternikhil.files.wordpress.com/2013/07/images-2.jpg"><img alt="Youtube Image" class="size-full wp-image-140 aligncenter" src="http://dotnetternikhil.files.wordpress.com/2013/07/images-2.jpg" height="169" width="299" /></a><br />
<br />
Now, Its Time for Searching the Videos in Youtube and play that Video in our Application so easily..!<br />
<br />
Now Here is the Design (.xaml) file of my Youtube Search Application.<br />
<blockquote>
<phone:PhoneApplicationPage<br />
x:Class="Nikhil'sYoutubeSearchApp.MainPage"<br />
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"<br />
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"<br />
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"<br />
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"<br />
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"<br />
FontFamily="{StaticResource PhoneFontFamilyNormal}"<br />
FontSize="{StaticResource PhoneFontSizeNormal}"<br />
Foreground="{StaticResource PhoneForegroundBrush}"<br />
SupportedOrientations="Portrait" Orientation="Portrait"<br />
shell:SystemTray.IsVisible="True"><br />
<phone:PhoneApplicationPage.Resources><br />
<DataTemplate x:Key="SearchTemplate"><br />
<Grid Margin="0,0,0,30"><br />
<TextBlock Text="{Binding Title}" VerticalAlignment="Top" HorizontalAlignment="Left" Width="355" Margin="120,0,0,0" TextWrapping="Wrap" /><br />
<Image Source="{Binding VideoImg}" HorizontalAlignment="Left" Width="100" Height="100" Stretch="UniformToFill"/><br />
</Grid><br />
</DataTemplate><br />
</phone:PhoneApplicationPage.Resources><br />
<!--LayoutRoot is the root grid where all page content is placed--><br />
<Grid x:Name="LayoutRoot" Background="Transparent"><br />
<Grid.RowDefinitions><br />
<RowDefinition Height="Auto"/><br />
<RowDefinition Height="*"/><br />
</Grid.RowDefinitions><br />
<br />
<!--TitlePanel contains the name of the application and page title--><br />
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"><br />
<TextBox Height="72" Name="TxtSearch" Text="" Width="460" SelectionBackground="#FF75A9C2" ><br />
<TextBox.Background><br />
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"><br />
<GradientStop Color="#FF6E704D" Offset="0.884"/><br />
<GradientStop Color="#FFB0BA87"/><br />
</LinearGradientBrush><br />
</TextBox.Background><br />
</TextBox><br />
<Button Content="Button" HorizontalAlignment="Right" Height="72" Name="BtnSearch" Width="160" RenderTransformOrigin="0.5,0.5" Click="BtnSearch_Click"><br />
<Button.Background><br />
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0"><br />
<GradientStop Color="#FF113B60" Offset="1"/><br />
<GradientStop Color="#FF8DBFDA"/><br />
</LinearGradientBrush><br />
</Button.Background><br />
</Button><br />
</StackPanel><br />
<br />
<!--ContentPanel - place additional content here--><br />
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"><br />
<ListBox HorizontalAlignment="Left" Margin="0,0,0,0" Height="600" ItemTemplate="{StaticResource SearchTemplate}" ItemsSource="{Binding SearchResults}" x:Name="LstVideobox" VerticalAlignment="Top" Width="460" SelectionChanged="LstVideobox_SelectionChanged"><br />
<ListBox.Background><br />
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"><br />
<GradientStop Color="#FF413D31"/><br />
<GradientStop Color="#FF54564F" Offset="0.457"/><br />
</LinearGradientBrush><br />
</ListBox.Background><br />
</ListBox><br />
</Grid><br />
</Grid><br />
<br />
</phone:PhoneApplicationPage></blockquote>
<br />
<br />
And Now the Code File for that is.. (xaml.cs)<br />
<blockquote>
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Net;<br />
using System.Windows;<br />
using System.Windows.Controls;<br />
using Microsoft.Phone.Tasks;<br />
using System.Windows.Documents;<br />
using System.Windows.Input;<br />
using System.Windows.Media;<br />
using System.Windows.Media.Animation;<br />
using System.Windows.Shapes;<br />
using System.Xml.Linq;<br />
using Microsoft.Phone.Controls;<br />
<br />
namespace Nikhils_YoutubeSearch_App<br />
{<br />
public partial class MainPage : PhoneApplicationPage<br />
{<br />
// Constructor<br />
public MainPage()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void BtnSearch_Click(object sender, RoutedEventArgs e)<br />
{<br />
var wc = new WebClient();<br />
wc.DownloadStringCompleted += DownloadStringCompleted;<br />
var src = string.Format("http://gdata.youtube.com/feeds/api/videos?q={0}&format=6", HttpUtility.UrlEncode(TxtSearch.Text));<br />
wc.DownloadStringAsync(new Uri(src));<br />
}<br />
<br />
void DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)<br />
{<br />
var atomns = XNamespace.Get("http://www.w3.org/2005/Atom");<br />
var medians = XNamespace.Get("http://search.yahoo.com/mrss/");<br />
var xml = XElement.Parse(e.Result);<br />
var videos = (from entry in xml.Descendants(atomns.GetName("entry"))<br />
select new VideoClass<br />
{<br />
VideoID = entry.Element(atomns.GetName("id")).Value,<br />
VideoImg = (from thumbnail in entry.Descendants(medians.GetName("thumbnail"))<br />
where thumbnail.Attribute("height").Value == "360"<br />
select thumbnail.Attribute("url").Value).FirstOrDefault(),<br />
Title = entry.Element(atomns.GetName("title")).Value<br />
}).ToArray();<br />
LstVideobox.ItemsSource = videos;<br />
}<br />
<br />
private void LstVideobox_SelectionChanged(object sender, SelectionChangedEventArgs e)<br />
{<br />
var curvid = LstVideobox.SelectedItem as VideoClass;<br />
if (curvid != null)<br />
{<br />
var parsedvid = curvid.VideoID.Split('/');<br />
var id = parsedvid[parsedvid.Length - 1];<br />
var url = "vnd.youtube:" + id;<br />
<br />
var myfinalurl = "https://www.youtube.com/embed/" + id;<br />
<br />
var tempurl = "https://www.youtube.com/watch?v=" + id + "?autoplay=1";<br />
<br />
var task = new WebBrowserTask { URL = "https://www.youtube.com/embed/" + id + "?autoplay=1" };<br />
task.Show();<br />
}<br />
}<br />
}<br />
}<br />
<br />
<br />
<br />
Now, Finally you created a Application of Youtube Searching and Playing that video.,,!!<br />
:)</blockquote>
</div>
Anonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.com0tag:blogger.com,1999:blog-8988662072008044107.post-65420825774373864462014-07-23T00:00:00.000+05:302014-12-20T17:35:44.306+05:30Show Pop Up menu in Windows Phone<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: center;">
<a href="http://dotnetternikhil.files.wordpress.com/2013/07/popup.png"><img alt="popup" class="size-medium wp-image-120 aligncenter" src="http://dotnetternikhil.files.wordpress.com/2013/07/popup.png?w=300" height="231" width="300" /></a></div>
Now, I show you how to display pop up menu in windows phone 7. and how can we handle it.<br />
<br />
for that you have to create a user control that is your pop up screen. and that is displayed in our home screen in windows phone.<br />
<br />
<blockquote>
<br />
// Place your Design of your User Control here</blockquote>
<br />
<br />
<br />
And this is the code behind of User Control as MyUserControl.xaml.cs.<br />
<blockquote>
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Net;<br />
using System.Windows;<br />
using System.Windows.Controls;<br />
using System.Windows.Documents;<br />
using System.Windows.Input;<br />
using System.Windows.Media;<br />
using System.Windows.Media.Animation;<br />
using System.Windows.Shapes;<br />
using System.Windows.Navigation;<br />
using System.Windows.Controls.Primitives;<br />
using Microsoft.Phone.Controls;<br />
using Microsoft.Xna.Framework;<br />
using Microsoft.Xna.Framework.GamerServices;<br />
using Microsoft.Xna.Framework.Media;<br />
<br />
namespace NikhilsProject<br />
{<br />
public partial class MyPopUpScreen : UserControl<br />
{<br />
public MyPopUpScreen(String message)<br />
{<br />
InitializeComponent();<br />
<br />
txtMessage.Text = message;<br />
txtMessageShadow.Text = message;<br />
}<br />
<br />
public void btnYes_Click(object sender, RoutedEventArgs e)<br />
{<br />
// Code that will fire when user clicks Yes button.<br />
}<br />
<br />
public void btnNotNow_Click(object sender, RoutedEventArgs e)<br />
{<br />
// Code that will fire when user clicks Not Now button.<br />
}<br />
<br />
private void ClosePopup()<br />
{<br />
Popup buyPop = this.Parent as Popup;<br />
buyPop.IsOpen = false;<br />
}<br />
}<br />
}</blockquote>
<br />
So, Now open HomePage.xaml.cs for display pop up at specific location and you have to handle that pop up. This code helps you.<br />
<blockquote>
<br />
Popup MusicPlaying = new Popup();<br />
MusicPlaying.Child = new MyPopUpScreen("Do you want to Stop Music Player");<br />
MusicPlaying.IsOpen = true;<br />
MusicPlaying.VerticalOffset = 100;<br />
MusicPlaying.HorizontalOffset = 25;<br />
MusicPlaying.Closed += (s1, e1) =><br />
{<br />
// Add you code here to do something<br />
// when the Popup is closed<br />
};</blockquote>
<br />
<br />
Please see the namespace also that i have used in my project;<br />
<br />
And, yup its Done Easily...!!</div>
Anonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.com3tag:blogger.com,1999:blog-8988662072008044107.post-62497571102319865412014-06-08T12:17:00.000+05:302014-12-20T17:36:15.573+05:30Display GIF or Animated Images in Windows Phone<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="http://dotnetternikhil.files.wordpress.com/2013/07/images-11.jpg"><img alt="GIF in WP" class="size-full wp-image-99 aligncenter" src="http://dotnetternikhil.files.wordpress.com/2013/07/images-11.jpg" height="218" width="231" /></a><br />
<br />
Unfortunately Windows Phone does not support animated images or .Gif Image Files.<br />
Then sometimes in our application we wish to display some animation images so that our application looks good.<br />
Now, if you have some gif or animated images and you wish to display that image in ur windows phone application.<br />
So, first of all you divide your gif images into frames using software like 'GIFFrame' or online. and this gives you a different frames of your gif files in to .png format.<br />
And Now,<br />
in Xaml.cs file, i show you that how can we display that group of images that looks like a animated image.<br />
<br />
So, Look, i used DispatcherTimer for executing tasks at some interval of time and with some priority also.<br />
For that you have to add namespace "System.Windows.Threading".<br />
<br />
<b>DispatcherTimer dtimer = new DispatcherTimer();</b><br />
<br />
And Now, you have to add list of all of that image frame files..<br />
<br />
<br />
<blockquote>
<br />
List<String> myFiles = new List<string>()<br />
{<br />
"Monkey_Images/img_tablet1.png",<br />
"Monkey_Images/img_tablet2.png",<br />
"Monkey_Images/img_tablet3.png",<br />
"Monkey_Images/img_tablet4.png",<br />
"Monkey_Images/img_tablet5.png",<br />
"Monkey_Images/img_tablet6.png",<br />
"Monkey_Images/img_tablet7.png"<br />
};</blockquote>
<br />
<br />
<br />
And now, you need a temporary list that stores all images that you are having to display. so i used List<BitmapImage>. for that you have to add namespace <br />
<br />
<blockquote>
"System.Windows.Media.Imaging".</blockquote>
<br />
<br />
<br />
<br />
<br />
<blockquote>
<br />
List bmps = new List() { };</blockquote>
<br />
<br />
<br />
And now, the logic is started..<br />
<br />
The Whole Code is:<br />
<b>in your Xaml.cs file..</b><br />
<br />
<blockquote>
<br />
int flag = 1;<br />
int current = 0;<br />
<br />
DispatcherTimer dtimer = new DispatcherTimer();<br />
<br />
List myFiles = new List() <br />
{ <br />
"Monkey_Images/img_tablet1.png", <br />
"Monkey_Images/img_tablet2.png", <br />
"Monkey_Images/img_tablet3.png", <br />
"Monkey_Images/img_tablet4.png", <br />
"Monkey_Images/img_tablet5.png",<br />
"Monkey_Images/img_tablet6.png", <br />
"Monkey_Images/img_tablet7.png"<br />
};<br />
<br />
List bmps = new List() { };<br />
public HomePage()<br />
{<br />
InitializeComponent();<br />
MonkeyMovement(); <br />
}<br />
<br />
public void MonkeyMovement()<br />
{ <br />
foreach (string ff in myFiles)<br />
{<br />
BitmapImage bmp = new BitmapImage(new Uri(ff, UriKind.Relative));<br />
bmps.Add(bmp); // Temporary assign images into bitmapimage list.<br />
}<br />
dtimer.Interval = TimeSpan.FromMilliseconds(20);<br />
dtimer.Tick += new EventHandler(dtimer_Tick);<br />
dtimer.Start();<br />
}<br />
<br />
void dtimer_Tick(Object sender, EventArgs e)<br />
{<br />
<br />
if (flag == 1)<br />
{<br />
monkeyImage.Source = bmps[current];<br />
//where monkey image is your image's Name in Xaml page.<br />
current++;<br />
if (current == bmps.Count - 1)<br />
{<br />
flag = 0;<br />
}<br />
}<br />
if (flag == 0)<br />
{<br />
monkeyImage.Source = bmps[current];<br />
current--;<br />
if (current == 0)<br />
{<br />
flag = 1;<br />
}<br />
}<br />
<br />
}</blockquote>
</div>
Anonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.com1tag:blogger.com,1999:blog-8988662072008044107.post-71927921436349683752014-06-05T15:55:00.000+05:302014-12-20T17:37:02.888+05:30Application Bar in Windows Phone 7<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
<a href="http://dotnetternikhil.files.wordpress.com/2013/06/app-bar.png"><img alt="App Bar" class="alignnone size-full wp-image-66" src="http://dotnetternikhil.files.wordpress.com/2013/06/app-bar.png" height="129" width="157" /></a></div>
<br />
<div>
In this article I am going to see how to use <b>Application Bar</b> effectively for a Windows Phone 7 Application development.</div>
<br />
<div>
</div>
<br />
<blockquote>
<br />
<div>
Application Bar is a set of Icons that can be configured at the bottom of the application for each page or also we can configure it for multiple pages.</div>
<br />
<div>
</div>
</blockquote>
<br />
<div>
These buttons can be used to navigate to frequently used pages across the application which enables users to navigate quickly and easily. Application bar has some set of options along with the buttons we can configure the menu items especially for some navigation which are not that much frequently used. Application bar automatically adjusts its icons and button as the screen orientation changes as and when.</div>
<br />
<div>
</div>
<br />
<div>
<br />
<br />
<br />
<blockquote>
<br />
<phone:PhoneApplicationPage.ApplicationBar><br />
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"><br />
<shell:ApplicationBarIconButton IconUri="/images/appbar.back.rest.png" Text="Back" Click="ApplicationBarIconButton_Click" /><br />
<shell:ApplicationBarIconButton IconUri="/images/appbar.add.rest.png" Text="Add" Click="ApplicationBarIconButton_Click_1"/><br />
<shell:ApplicationBarIconButton IconUri="/images/appbar.next.rest.png" Text="Next" Click="ApplicationBarIconButton_Click_2" /><br />
<shell:ApplicationBar.MenuItems><br />
<shell:ApplicationBarMenuItem Text="Submit" /><br />
<shell:ApplicationBarMenuItem Text="Clear" /><br />
</shell:ApplicationBar.MenuItems><br />
</shell:ApplicationBar><br />
</phone:PhoneApplicationPage.ApplicationBar></blockquote>
<br />
<br />
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/12534619758140205443noreply@blogger.com0