tag:blogger.com,1999:blog-55817526522062362822024-03-13T18:11:53.077-07:00DotnetExamplesAnkush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-5581752652206236282.post-13926593533400391802013-12-11T03:24:00.000-08:002013-12-11T03:41:17.599-08:00Exception Handling in ASP.NET MVC 4<div dir="ltr" style="text-align: left;" trbidi="on">
<ol>
<div style="margin-bottom: 0cm;">
<span style="background-color: #eeeeee; font-family: Calibri, sans-serif;"><span style="color: #222222;">What
does the user see when a runtime error occurs in an ASP.NET web
application? The answer depends on how the website's </span><span style="color: #222222;"><b><customErrors></b></span><span style="color: #222222;">
configuration. By default, users are shown an unsightly yellow
screen proclaiming that a runtime error has occurred. This tutorial
shows how to customize settings</span> to handle
runtime exceptions.</span></div>
</ol>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Calibri, sans-serif;"><span style="font-size: small;"> <span style="color: #0084d1;"><span style="font-size: 15pt;">We
will use two attributes to handle error in an MVC application</span></span></span></span></div>
<ul>
<li><div style="margin-bottom: 0cm;">
<span style="font-family: Calibri, sans-serif;"><b>customErrors
attribute</b> defined in web.config</span></div>
</li>
<li><div style="margin-bottom: 0cm;">
<span style="font-family: Calibri, sans-serif;"><b>HandleError
attribute</b> comes with default MVC Application</span></div>
</li>
</ul>
<div>
<ol style="text-align: left;">
<li><span style="font-family: Calibri, sans-serif;">Set </span><b style="font-family: Calibri, sans-serif;">custom errors mode</b><span style="font-family: Calibri, sans-serif;"> </span><span style="font-family: Calibri, sans-serif;">to</span><span style="font-family: Calibri, sans-serif;"> </span><b style="font-family: Calibri, sans-serif;">ON</b><span style="font-family: Calibri, sans-serif;"> </span><span style="font-family: Calibri, sans-serif;">in web config.</span></li>
<div style="margin-bottom: 0cm;">
<ul>
<li><span style="font-family: Calibri, sans-serif;">From custom error we can set that where we can redirect a user when some exception occurs in our application.</span></li>
<li><span style="font-family: Calibri, sans-serif;">Set </span><b style="font-family: Calibri, sans-serif;">defaultRedirect</b><span style="font-family: Calibri, sans-serif;"> </span><span style="font-family: Calibri, sans-serif;">attribute'value & add a sub tag for 404 error. Values for</span><span style="font-family: Calibri, sans-serif;"> </span><b style="font-family: Calibri, sans-serif;">defaultRediret</b><span style="font-family: Calibri, sans-serif;"> </span><span style="font-family: Calibri, sans-serif;">and</span><span style="font-family: Calibri, sans-serif;"> </span><b style="font-family: Calibri, sans-serif;">redirect</b><span style="font-family: Calibri, sans-serif;"> </span><span style="font-family: Calibri, sans-serif;">are the URLs of the pages for default redirection when some error occurs.</span></li>
</ul>
<span style="color: blue;"><span style="font-size: 9pt;"></span></span><br />
<ol><div style="margin-bottom: 0cm;">
<span style="color: blue;"></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: blue;"><span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><!--</span></span><span style="color: green;"><span style="font-size: 9pt;"> Custom Error Handling </span></span><span style="color: blue;"><span style="font-size: 9pt;">--></span></span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: blue;"><span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><</span></span><span style="color: #a31515;"><span style="font-size: 9pt;">customErrors</span></span><span style="color: blue;"><span style="font-size: 9pt;"> </span></span><span style="color: red;"><span style="font-size: 9pt;">mode</span></span><span style="color: blue;"><span style="font-size: 9pt;">=</span></span><span style="color: black;"><span style="font-size: 9pt;">"</span></span><span style="color: blue;"><span style="font-size: 9pt;">On</span></span><span style="color: black;"><span style="font-size: 9pt;">"</span></span><span style="color: blue;"><span style="font-size: 9pt;"> </span></span><span style="color: red;"><span style="font-size: 9pt;">defaultRedirect</span></span><span style="color: blue;"><span style="font-size: 9pt;">=</span></span><span style="color: black;"><span style="font-size: 9pt;">"</span></span><span style="color: blue;"><span style="font-size: 9pt;">~/Home/DefaultError</span></span><span style="color: black;"><span style="font-size: 9pt;">"</span></span><span style="color: blue;"><span style="font-size: 9pt;">></span></span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: blue;"><span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><</span></span><span style="color: #a31515;"><span style="font-size: 9pt;">error</span></span><span style="color: blue;"><span style="font-size: 9pt;"> </span></span><span style="color: red;"><span style="font-size: 9pt;">statusCode</span></span><span style="color: blue;"><span style="font-size: 9pt;">=</span></span><span style="color: black;"><span style="font-size: 9pt;">"</span></span><span style="color: blue;"><span style="font-size: 9pt;">404</span></span><span style="color: black;"><span style="font-size: 9pt;">"</span></span><span style="color: blue;"><span style="font-size: 9pt;"> </span></span><span style="color: red;"><span style="font-size: 9pt;">redirect</span></span><span style="color: blue;"><span style="font-size: 9pt;">=</span></span><span style="color: black;"><span style="font-size: 9pt;">"</span></span><span style="color: blue;"><span style="font-size: 9pt;">~/Home/Error404</span></span><span style="color: black;"><span style="font-size: 9pt;">"</span></span><span style="color: blue;"><span style="font-size: 9pt;"> /></span></span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: blue;"><span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"></</span></span><span style="color: #a31515;"><span style="font-size: 9pt;">customErrors</span></span><span style="color: blue;"><span style="font-size: 9pt;">></span></span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: blue;"><span style="color: blue;"><span style="font-size: 9pt;"><br /></span></span></span></div>
</ol>
<br />
<br />
<li><span style="font-family: Calibri, sans-serif;">Use </span><b style="font-family: Calibri, sans-serif;">HandleError</b><span style="font-family: Calibri, sans-serif;"> </span><span style="font-family: Calibri, sans-serif;">filter attribute</span></li>
<br />
<ul>
<li><span style="font-family: Calibri, sans-serif;">The</span><span style="font-family: Calibri, sans-serif;"> </span><i style="font-family: Calibri, sans-serif;">HandleError </i><span style="font-family: Calibri, sans-serif;">filter works only if the</span><span style="font-family: Calibri, sans-serif;"> </span><i style="font-family: Calibri, sans-serif;"><customErrors> </i><span style="font-family: Calibri, sans-serif;">section is turned on in web.config.</span></li>
<li><span style="font-family: Calibri, sans-serif;">HandleError attribute provided by MVC framework.</span></li>
<li><span style="font-family: Calibri, sans-serif;">It handle only</span><span style="font-family: Calibri, sans-serif;"> </span><b style="font-family: Calibri, sans-serif;">status code 500 </b><span style="font-family: Calibri, sans-serif;">errors. It does not handle 404 not found or other types of errors.</span></li>
<li><span style="font-family: Calibri, sans-serif;">If you use both</span><span style="font-family: Calibri, sans-serif;"> </span><b style="font-family: Calibri, sans-serif;">customError</b><span style="font-family: Calibri, sans-serif;"> </span><span style="font-family: Calibri, sans-serif;">attribute in web.config &</span><span style="font-family: Calibri, sans-serif;"> </span><b style="font-family: Calibri, sans-serif;">HandleError</b><span style="font-family: Calibri, sans-serif;"> </span><span style="font-family: Calibri, sans-serif;">attribute and any internal server error (500) occurs then</span><span style="font-family: Calibri, sans-serif;"> </span><b style="font-family: Calibri, sans-serif;">HandleError </b><span style="font-family: Calibri, sans-serif;">will override behaviour of</span><b style="font-family: Calibri, sans-serif;"> customError attribute </b><span style="font-family: Calibri, sans-serif;">& will handle error with it's own way.</span></li>
</ul>
</div>
</ol>
</div>
<ol>
<div style="margin-bottom: 0cm;">
</div>
</ol>
<ol start="2">
<div style="margin-bottom: 0cm;">
<span style="font-family: Calibri, sans-serif;"><i><u>Example
of Controller level handling</u></i></span></div>
<div style="margin-bottom: 0cm;">
</div>
</ol>
<pre class="western" style="text-indent: 2.14cm;"><span style="color: black;"><span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;">[HandleError]</span></span></span>
<span style="color: black;"><span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> HomeController : Controller</span></span></span>
<span style="color: black;"><span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;">{</span></span></span>
<span style="color: black;"> <span style="font-family: Calibri, sans-serif;"><span style="color: blue;"><span style="font-size: 9pt;">public</span></span><span style="font-size: 9pt;"> ActionResult Index()</span></span></span>
<span style="color: black;"> <span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;">{</span></span></span>
<span style="color: black;"> <span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;">ViewData[</span><span style="color: #a31515;"><span style="font-size: 9pt;">"Message"</span></span><span style="font-size: 9pt;">] = </span><span style="color: #a31515;"><span style="font-size: 9pt;">"Welcome to ASP.NET MVC!"</span></span><span style="font-size: 9pt;">;</span></span></span>
<span style="color: black;"> <span style="font-family: Calibri, sans-serif;"><span style="color: blue;"><span style="font-size: 9pt;">return</span></span><span style="font-size: 9pt;"> View();</span></span></span>
<span style="color: black;"> <span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;">}</span></span></span>
<span style="color: black;"> <span style="font-family: Calibri, sans-serif;"><span style="color: blue;"><span style="font-size: 9pt;">public</span></span><span style="font-size: 9pt;"> ActionResult About()</span></span></span>
<span style="color: black;"> <span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;">{</span></span></span>
<span style="color: black;"> <span style="font-family: Calibri, sans-serif;"><span style="color: blue;"><span style="font-size: 9pt;">return</span></span><span style="font-size: 9pt;"> View();</span></span></span>
<span style="color: black;"> <span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;">}</span></span></span>
<span style="color: black;"><span style="font-family: Calibri, sans-serif;"><span style="font-size: 9pt;">}</span></span></span>
</pre>
<div style="margin-bottom: 0cm;">
<br /></div>
<ol start="3" style="text-align: left;">
<li><div style="margin-bottom: 0cm;">
<span style="font-family: Calibri, sans-serif;">You
can use <b>HandleError </b>attribute
at </span></div>
</li>
<ul>
<li><span style="font-family: Calibri, sans-serif;">Action
Level – by adding this attribute on Action ex. </span><span style="color: #393124; font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><b>[</b></span></span><span style="color: #5353a6; font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><b>HandleError]</b></span></span></li>
<li><span style="font-family: Calibri, sans-serif;">Controller
Level - by adding this attribute on Controller ex. </span><span style="color: #393124; font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><b>[</b></span></span><span style="color: #5353a6; font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><b>HandleError]</b></span></span></li>
<li><span style="font-family: Calibri, sans-serif;">Application
Level - </span><span style="font-family: Calibri, sans-serif;">by
registering filter in </span><b style="font-family: Calibri, sans-serif;">FilterConfig.cs</b><span style="font-family: Calibri, sans-serif;"> in </span><b style="font-family: Calibri, sans-serif;">App_Start</b><span style="font-family: Calibri, sans-serif;">
folder</span></li>
</ul>
</ol>
<i style="font-family: Calibri, sans-serif;"><u>Example of Application level handling</u></i><br />
<div>
<div style="text-align: left;">
<span style="color: black;"> </span><span style="color: blue; font-family: Calibri, sans-serif;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">public</span></span></span><span style="color: black; font-family: Calibri, sans-serif;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">
</span></span></span><span style="color: blue; font-family: Calibri, sans-serif;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">class</span></span></span><span style="color: black; font-family: Calibri, sans-serif;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">
</span></span></span><span style="color: #2b91af; font-family: Calibri, sans-serif;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">FilterConfig</span></span></span></div>
<div style="margin-bottom: 0cm; text-align: left;">
<span style="color: black;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;"> {</span></span></span></div>
<div style="margin-bottom: 0cm; text-align: left;">
<span style="color: black;"></span><span style="color: blue;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;"> public</span></span></span><span style="color: black;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">
</span></span></span><span style="color: blue;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">static</span></span></span><span style="color: black;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">
</span></span></span><span style="color: blue;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">void</span></span></span><span style="color: black;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">
RegisterGlobalFilters(</span></span></span><span style="color: #2b91af;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">GlobalFilterCollection</span></span></span><span style="color: black;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">
filters)</span></span></span></div>
<div style="margin-bottom: 0cm; text-align: left;">
<span style="color: black;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;"> {</span></span></span></div>
<div style="margin-bottom: 0cm; text-align: left;">
<span style="color: black;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;"> filters.Add(</span></span></span><span style="color: blue;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">new</span></span></span><span style="color: black;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">
</span></span></span><span style="color: #2b91af;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">HandleErrorAttribute</span></span></span><span style="color: black;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;">());</span></span></span></div>
<div style="margin-bottom: 0cm; text-align: left;">
<span style="color: black;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;"> }</span></span></span></div>
<div style="margin-bottom: 0cm; text-align: left;">
<span style="color: black;"><span style="font-family: Consolas, sans-serif;"><span style="font-size: 9pt;"> }</span></span></span></div>
<ol>
<div style="margin-bottom: 0cm;">
</div>
</ol>
<ol start="3" style="text-align: left;">
<li><span style="font-family: Calibri, sans-serif;">When
error occurs, this will redirect to a view which is in </span><b style="font-family: Calibri, sans-serif;">shared
folder</b><span style="font-family: Calibri, sans-serif;"> named </span><b style="font-family: Calibri, sans-serif;">'Error'</b></li>
<li><span style="font-family: Calibri, sans-serif;">You
can change view name. ex. </span><span style="color: #393124; font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><b>[</b></span></span><span style="color: #5353a6; font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><b>HandleError</b></span></span><span style="color: #393124; font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><b>(</b></span></span><span style="color: #5353a6; font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><b>View</b></span></span><span style="color: #393124; font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><b>
= </b></span></span><span style="color: #ff6820; font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><b>"DatabaseError"</b></span></span><span style="color: #393124; font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><b>)]</b></span></span></li>
<li><span style="color: #393124; font-family: Calibri, sans-serif;">That's
all</span></li>
<li><span style="color: #393124; font-family: Calibri, sans-serif;">Redirection
sequence of error handling</span></li>
<ul>
<li><span style="color: #393124; font-family: Calibri, sans-serif;">For
( 500 Internal server error)</span></li>
<ol>
<li><span style="color: #393124; font-family: Calibri, sans-serif;">Redirect
to view of Handle Error Attribute</span></li>
<li><span style="color: #393124; font-family: Calibri, sans-serif;"><span style="font-size: small;">Redirect
to Url </span></span><span style="color: red; font-family: Calibri, sans-serif;"><span style="font-size: small;"><b>defaultRedirect</b></span></span><span style="color: #393124; font-family: Calibri, sans-serif;"><span style="font-size: small;">
defined in </span></span><span style="color: #a31515; font-family: Calibri, sans-serif;"><span style="font-size: small;"><b>customErrors</b></span></span><span style="color: #a31515; font-family: Calibri, sans-serif;"><span style="font-size: 9pt;"><b>
</b></span></span><span style="color: #393124; font-family: Calibri, sans-serif;"><span style="font-size: small;">tag
in web.config. ( if Handle Error is not registered at any level)</span></span></li>
</ol>
<li><span style="color: #393124; font-family: Calibri, sans-serif;">For
( 404 or other types of errors)</span></li>
<ol>
<li><span style="color: #393124; font-family: Calibri, sans-serif;"><span style="font-size: small;">Other
url according to status code defined in </span></span><span style="color: #a31515; font-family: Calibri, sans-serif;"><span style="font-size: small;"><b>customErrors</b></span></span><span style="color: #a31515; font-family: Calibri, sans-serif;"><span style="font-size: small;">
</span></span><span style="color: #393124; font-family: Calibri, sans-serif;"><span style="font-size: small;">tag.</span></span></li>
</ol>
</ul>
</ol>
<br />
<div style="margin-bottom: 0cm;">
<span style="color: blue;"> <span style="font-family: Calibri, sans-serif;"><span style="font-size: small;">Note:
</span></span></span>
</div>
<ol>
<div style="margin-bottom: 0cm;">
</div>
<li><div style="margin-bottom: 0cm;">
<span style="color: #393124;"><span style="font-family: Calibri, sans-serif;">Handle
Error is an inbuilt Filter. We can use our own custom filter
attribute by making a class which is derived from Filter Attribute &
implements Iexception Filter interface. </span></span>
</div>
</li>
<li><div style="margin-bottom: 0cm;">
<span style="font-family: Calibri, sans-serif;"><span style="color: #393124;">To
handle ajax request's exception. Visit the link given below.</span></span></div>
</li>
<li><div style="margin-bottom: 0cm;">
<span style="color: #393124;"><span style="font-family: Calibri, sans-serif;">For
more detail about exception. Visit this link :</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: #393124;"><span style="font-family: Times New Roman, serif;"><span style="font-size: small;"><span style="font-family: Calibri, sans-serif;"><a href="http://www.dotnet-tricks.com/Tutorial/mvc/19D9140313-Exception-or-Error-Handling-and-Logging-in-MVC4.html">http://www.dotnet-tricks.com/Tutorial/mvc/19D9140313-Exception-or-Error-Handling-and-Logging-in-MVC4.html</a>
</span></span></span></span>
</div>
</li>
</ol>
<div style="margin-bottom: 0cm;">
<br /></div>
</div>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-56095923382625691932013-12-08T02:57:00.000-08:002013-12-08T02:57:55.520-08:00 How to implement Simple Membership in MVC 4<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="Standard">
<span style="font-family: Verdana, sans-serif;">Importanat Note: We can initialize simple Membership in MVC 4 by two ways. </span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span style="font-family: Verdana, sans-serif;"> 1. By InitializeSimpleMembershipAttribute which is already present on Account Controller.</span></div>
<div class="Standard">
<span style="font-family: Verdana, sans-serif;"> 2. FromGlobal.asax.</span></div>
<div class="Standard">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="Standard">
<span style="font-family: Verdana, sans-serif;">Here we are implementing it with second way. </span></div>
<div class="Standard">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="Standard">
<span style="font-family: Verdana, sans-serif;">So First of all remove InitializeSimpleMembershipAttribute from Account Controller and follow these steps.</span></div>
<div class="Standard">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="Standard">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="Standard">
<span lang="EN-IN"><span style="font-family: Verdana, sans-serif;"> 1. Copy this function in Global.asax</span> </span></div>
<div class="Standard">
<span lang="EN-IN"><br /></span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt;">void</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> initializeMembership()</span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt;">if</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> (!</span><span lang="EN-IN" style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">WebSecurity</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">.Initialized)</span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">WebSecurity</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">.InitializeDatabaseConnection(</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"ConnectionString"</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">, </span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"UserProfile"</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">, </span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"UserId"</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">, </span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"UserName"</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">, autoCreateTables: </span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt;">true</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">);</span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span lang="EN-IN"></span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"><br /></span></div>
<div class="Standard">
<span lang="EN-IN" style="font-size: 9.5pt;"><span style="font-family: Verdana, sans-serif;"><br /></span></span></div>
<div class="Standard">
<span style="font-family: Verdana, sans-serif;"><span lang="EN-IN">2. This function checks the database of given </span><span style="color: #a31515;">ConnectionString. </span>Create Membership Table if they are not present, and initializes Simple Membership.</span></div>
<div class="Standard">
<span style="font-family: Consolas; font-size: 13px;"><br /></span></div>
<div class="Standard" style="margin-left: 0in; mso-list: l0 level1 lfo1; text-indent: 0in;">
<span style="font-family: Verdana, sans-serif;"><span lang="EN-IN">3.<span style="font-size: 7pt;"> </span></span><span lang="EN-IN">Call this function in the end of </span><span style="font-size: 13px;">Application_Start </span><span style="text-indent: 0in;">event. Like given below.</span></span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> protected</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">void</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> Application_Start()</span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">AreaRegistration</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">.RegisterAllAreas();</span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> RegisterGlobalFilters(</span><span lang="EN-IN" style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">GlobalFilters</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">.Filters);</span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> RegisterRoutes(</span><span lang="EN-IN" style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">RouteTable</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">.Routes);</span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">
initializeMembership();<o:p></o:p></span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> </span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> </span></div>
<div class="Standard" style="margin-left: 0in; mso-list: l0 level1 lfo1; text-indent: 0in;">
<span style="font-family: Verdana, sans-serif;"><span lang="EN-IN">4. </span><span lang="EN-IN">Tables for
membership have now been created in DataBase of given Connection string.</span></span></div>
<div class="Standard" style="margin-left: 0in; mso-list: l0 level1 lfo1; text-indent: 0in;">
<span style="font-family: Verdana, sans-serif;"><span lang="EN-IN"><br /></span></span></div>
<div class="Standard" style="margin-left: 0in; mso-list: l0 level1 lfo1; text-indent: 0in;">
<span style="font-family: Verdana, sans-serif;"><span lang="EN-IN">5. </span><span lang="EN-IN">You can also add
more fields in UserProfile Table. (Not mentioning here now)</span></span></div>
<div class="Standard" style="margin-left: 0in; mso-list: l0 level1 lfo1; text-indent: 0in;">
<span style="font-family: Verdana, sans-serif;"><span lang="EN-IN"><br /></span></span></div>
<div class="Standard" style="margin-left: 0in; mso-list: l0 level1 lfo1; text-indent: 0in;">
<span style="font-family: Verdana, sans-serif;"><span lang="EN-IN">6. </span><span lang="EN-IN">Now add
default login url in system.web node in web config if not present.</span></span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> </span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> <</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">authentication</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </span><span lang="EN-IN" style="color: red; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">mode</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">=</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">Forms</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> <</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">forms</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </span><span lang="EN-IN" style="color: red; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">loginUrl</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">=</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">~/Account/Login</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </span><span lang="EN-IN" style="color: red; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">timeout</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">=</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">2880</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> /></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">authentication</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"><br /></span></div>
<div class="Standard" style="margin-left: 0in; mso-list: l0 level1 lfo1; text-indent: 0in;">
<span style="font-family: Verdana, sans-serif;"><span lang="EN-IN"><br /></span></span></div>
<div class="Standard" style="margin-left: 0in; mso-list: l0 level1 lfo1; text-indent: 0in;">
<span style="font-family: Verdana, sans-serif;"><span lang="EN-IN">7. </span><span lang="EN-IN">Also add
some other settings in system.web in web config. This setting enables </span><span class="SourceText"><span lang="EN-IN" style="background-color: #eeeeee;">SimpleMembershipProvider</span></span><span class="SourceText"><span lang="EN-IN" style="background-color: #eeeeee;"> </span></span><span lang="EN-IN"> explicitly.</span></span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> </span></div>
<div class="Standard">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"><!--</span><span lang="EN-IN" style="color: green; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">MVC 4 Simple Membership Settings</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">--></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> <</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">roleManager</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </span><span lang="EN-IN" style="color: red; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">enabled</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">=</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">true</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </span><span lang="EN-IN" style="color: red; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">defaultProvider</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">=</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">SimpleRoleProvider</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> <</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">providers</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> <</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">clear</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">/></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> <</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">add</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </span><span lang="EN-IN" style="color: red; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">name</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">=</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">SimpleRoleProvider</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </span><span lang="EN-IN" style="color: red; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">type</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">=</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">WebMatrix.WebData.SimpleRoleProvider,
WebMatrix.WebData</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">/></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">providers</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">roleManager</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> <</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">membership</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </span><span lang="EN-IN" style="color: red; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">defaultProvider</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">=</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">SimpleMembershipProvider</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> <</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">providers</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> <</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">clear</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">/></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> <</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">add</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </span><span lang="EN-IN" style="color: red; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">name</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">=</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">SimpleMembershipProvider</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </span><span lang="EN-IN" style="color: red; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">type</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">=</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">WebMatrix.WebData.SimpleMembershipProvider,
WebMatrix.WebData</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt;">"</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> /></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">providers</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </</span><span lang="EN-IN" style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">membership</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> <o:p></o:p></span></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> <!--</span><span lang="EN-IN" style="color: green; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">End of MVC 4 Simple Membership Settings</span><span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;">--></span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: Consolas;"> </span></div>
<div class="Standard">
<br /></div>
<div class="Standard" style="margin-left: 0in; mso-list: l0 level1 lfo1; text-indent: 0in;">
</div>
<div class="Standard">
<br /></div>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-49781887747256507722013-08-23T12:30:00.002-07:002013-08-23T12:30:51.477-07:00Difference between Routing and URL Rewriting<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: #f9f9f9; color: #161616; font-family: Arial, Tahoma, Georgia, sans-serif; font-size: 13px; line-height: 24px; padding-left: 20px; padding-top: 10px; text-align: justify;">
Many developers compares routing to URL rewritting that is wrong. Since both the approaches are very much different. Moreover, both the approaches can be used to make SEO friendly URLs. Below is the main difference between these two approaches.</div>
<ol class="orderlist" style="background-color: #f9f9f9; color: #161616; font-family: Arial, Tahoma, Georgia, sans-serif; font-size: 13px; font-weight: bold; line-height: 24px; margin-left: 2px;">
<li style="padding: 5px 0px; text-align: justify;"><div style="font-weight: normal; padding: 0px;">
URL rewriting is focused on mapping one URL (new url) to another URL (old url) while routing is focused on mapping a URL to a resource.</div>
</li>
<li style="padding: 5px 0px; text-align: justify;"><div style="font-weight: normal; padding: 0px;">
Actually, URL rewriting rewrites your old url to new one while routing never rewrite your old url to new one but it map to the original route.</div>
</li>
</ol>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-92124018508207712322013-08-23T11:48:00.000-07:002013-08-23T11:51:05.595-07:00Different Types of SQL Keys<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: #f9f9f9; color: #161616; font-family: Arial, Tahoma, Georgia, sans-serif; font-size: 13px; line-height: 24px; padding-left: 20px; padding-top: 10px; text-align: justify;">
We have following types of keys in SQL which are used to fetch records from tables and to make relationship among tables or views.</div>
<ol class="orderlist" style="background-color: #f9f9f9; color: #161616; font-family: Arial, Tahoma, Georgia, sans-serif; font-size: 13px; font-weight: bold; line-height: 24px; margin-left: 2px;">
<li style="padding: 5px 0px; text-align: justify;"><h2 style="background-position: 0px 50%; color: #363636; font-family: Georgia, sans-serif; font-size: 12pt; line-height: 23px; margin: 0px; padding: 0px 0px 5px; text-shadow: rgb(255, 255, 255) -1px -1px 0px;">
Super Key</h2>
<div style="font-weight: normal; padding: 0px;">
Super key is a set of one or more than one keys that can be used to identify a record uniquely in a table.<b>Example :</b> Primary key, Unique key, Alternate key are subset of Super Keys.</div>
</li>
<li style="padding: 5px 0px; text-align: justify;"><h2 style="background-position: 0px 50%; color: #363636; font-family: Georgia, sans-serif; font-size: 12pt; line-height: 23px; margin: 0px; padding: 0px 0px 5px; text-shadow: rgb(255, 255, 255) -1px -1px 0px;">
Candidate Key</h2>
<div style="font-weight: normal; padding: 0px;">
A Candidate Key is a set of one or more fields/columns that can identify a record uniquely in a table. There can be multiple Candidate Keys in one table. Each Candidate Key can work as Primary Key.</div>
<div style="font-weight: normal; padding: 0px;">
<br /></div>
</li>
<li style="padding: 5px 0px; text-align: justify;"><h2 style="background-position: 0px 50%; color: #363636; font-family: Georgia, sans-serif; font-size: 12pt; line-height: 23px; margin: 0px; padding: 0px 0px 5px; text-shadow: rgb(255, 255, 255) -1px -1px 0px;">
Primary Key</h2>
<div style="font-weight: normal; padding: 0px;">
Primary key is a set of one or more fields/columns of a table that uniquely identify a record in database table. It can not accept null, duplicate values. Only one Candidate Key can be Primary Key.</div>
</li>
<li style="padding: 5px 0px; text-align: justify;"><h2 style="background-position: 0px 50%; color: #363636; font-family: Georgia, sans-serif; font-size: 12pt; line-height: 23px; margin: 0px; padding: 0px 0px 5px; text-shadow: rgb(255, 255, 255) -1px -1px 0px;">
Alternate key</h2>
<div style="font-weight: normal; padding: 0px;">
A Alternate key is a key that can be work as a primary key. Basically it is a candidate key that currently is not primary key.</div>
<div style="font-weight: normal; padding: 0px;">
<b>Example:</b> In below diagram RollNo and EnrollNo becomes Alternate Keys when we define ID as Primary Key.</div>
</li>
<li style="padding: 5px 0px; text-align: justify;"><h2 style="background-position: 0px 50%; color: #363636; font-family: Georgia, sans-serif; font-size: 12pt; line-height: 23px; margin: 0px; padding: 0px 0px 5px; text-shadow: rgb(255, 255, 255) -1px -1px 0px;">
Composite/Compound Key</h2>
<div style="font-weight: normal; padding: 0px;">
Composite Key is a combination of more than one fields/columns of a table. It can be a Candidate key, Primary key.</div>
</li>
<li style="padding: 5px 0px; text-align: justify;"><h2 style="background-position: 0px 50%; color: #363636; font-family: Georgia, sans-serif; font-size: 12pt; line-height: 23px; margin: 0px; padding: 0px 0px 5px; text-shadow: rgb(255, 255, 255) -1px -1px 0px;">
Unique Key</h2>
<div style="font-weight: normal; padding: 0px;">
Uniquekey is a set of one or more fields/columns of a table that uniquely identify a record in database table. It is like Primary key but it can accept only one null value and it can not have duplicate values. For more help refer the article <a class="link" href="http://www.dotnet-tricks.com/Tutorial/sqlserver/V2bS260912-Difference-between-Primary-Key-and-Unique-Key.html" style="color: #3171b0; font-size: 10pt; text-align: left; text-decoration: none; text-shadow: rgb(255, 255, 255) 1px 1px 0px;">Difference between primary key and unique key</a>.</div>
</li>
<li style="padding: 5px 0px; text-align: justify;"><h2 style="background-position: 0px 50%; color: #363636; font-family: Georgia, sans-serif; font-size: 12pt; line-height: 23px; margin: 0px; padding: 0px 0px 5px; text-shadow: rgb(255, 255, 255) -1px -1px 0px;">
Foreign Key</h2>
<div style="font-weight: normal; padding: 0px;">
Foreign Key is a field in database table that is Primary key in another table. It can accept multiple null, duplicate values. For more help refer the article <a class="link" href="http://www.dotnet-tricks.com/Tutorial/sqlserver/TENc260912-Difference-between-Primary-Key-and-Foreign-Key.html" style="color: #3171b0; font-size: 10pt; text-align: left; text-decoration: none; text-shadow: rgb(255, 255, 255) 1px 1px 0px;">Difference between primary key and foreign key</a>.</div>
<div style="font-weight: normal; padding: 0px;">
<b>Example :</b> We can have a DeptID column in the Employee table which is pointing to DeptID column in a department table where it a primary key.</div>
</li>
</ol>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-55912633307509299462013-05-05T12:04:00.001-07:002013-05-05T12:05:08.173-07:00How to use jQuery.noConflict<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; border: 0px; color: #333333; font-family: arial, helvetica, sans-serif; font-size: 13px; line-height: 22px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
Using jQuery.noConflict, you can make multiple versions of jQuery coexist on the same page. For instance</div>
<div style="background-color: white; border: 0px; color: #333333; font-family: arial, helvetica, sans-serif; font-size: 13px; line-height: 22px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
<br style="margin: 0px; padding: 0px;" /></div>
<div style="background-color: white; border: 0px; color: #333333; font-family: arial, helvetica, sans-serif; font-size: 13px; line-height: 22px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
</div>
<div class="__zd_findAndReplaceParent" style="background-color: white; border: 0px; color: #333333; font-family: arial, helvetica, sans-serif; font-size: 13px; height: 11px; line-height: 22px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
</div>
<div class="__zd_findAndReplace" style="background-color: #efefef; border: 0px; color: #333333; float: right; font-family: arial, helvetica, sans-serif; font-size: 13px; line-height: 22px; margin: 0px 30px 0px 0px; outline: 0px; padding: 0px 3px; text-align: right; vertical-align: baseline;">
<span style="background-color: transparent; border: 0px; color: blue; cursor: pointer; font-family: 'trebuchet ms', arial; font-size: 10px; line-height: normal; margin: 0px; outline: 0px; padding: 0px; text-decoration: underline; vertical-align: baseline;">Copy code</span></div>
<pre class="highlight"><script src="jquery-1.3.2.js"></script>
<script>
var jq132 = jQuery.noConflict();
</script>
<script src="jquery-1.4.2.js"></script>
<script>
var jq142 = jQuery.noConflict();
</script>
</pre>
<pre class="highlight"></pre>
<div style="background-color: white; border: 0px; color: #333333; font-family: arial, helvetica, sans-serif; font-size: 13px; line-height: 22px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
<br /></div>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-68342092353691765542013-05-05T11:37:00.000-07:002013-05-05T11:38:18.747-07:00ASP.NET Forms Authentication "Remember Me"<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #474c55; font-family: Titillium-Regular, sans-serif; font-size: 15px; line-height: 19.0625px;">Today I needed to set up a "remember me" functionality for website's </span><span style="background-color: white; color: #474c55; font-family: Titillium-Regular, sans-serif; font-size: 15px; line-height: 19.0625px;">login pages. If you ever tried to achieve this using .NET's FormsAuthentication, you might have noticed that... it's just not working. Even if you pass the "createPersistentCookie" parameter value as "true" when initializing FormsAuthentication - the cookie still lives for a limited time only - the time specified as the Forms-Authentication timeout in "web.config". Then the cookie dies.</span><br />
<br style="background-color: white; color: #474c55; font-family: Titillium-Regular, sans-serif; font-size: 15px; line-height: 19.0625px;" />
<span style="background-color: white; color: #474c55; font-family: Titillium-Regular, sans-serif; font-size: 15px; line-height: 19.0625px;">The only solution was to increase that timeout value in web.config. And it's not a very good idea because of the security reasons.</span><br />
<br style="background-color: white; color: #474c55; font-family: Titillium-Regular, sans-serif; font-size: 15px; line-height: 19.0625px;" />
<span style="background-color: white; color: #474c55; font-family: Titillium-Regular, sans-serif; font-size: 15px; line-height: 19.0625px;">The solution is to set the authentication cookie timeout explicitly. See the code, which is pretty self-explaining:</span><br />
<br />
<pre class="highlight">private void FormsAuthLogin(string userName, bool rememberMe)
{
if (!rememberMe)
{
FormsAuthentication.RedirectFromLoginPage(userName, false);
}
else
{
FormsAuthentication.Initialize();
DateTime expires = DateTime.Now.AddDays(20);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
userName,
DateTime.Now,
expires, // value of time out property
true, // Value of IsPersistent property
String.Empty,
FormsAuthentication.FormsCookiePath);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie authCookie = new HttpCookie(
FormsAuthentication.FormsCookieName,
encryptedTicket);
authCookie.Expires = expires;
Response.Cookies.Add(authCookie);
string returnUrl = FormsAuthentication.GetRedirectUrl(userName, true);
if (string.IsNullOrEmpty(returnUrl)) returnUrl = "Default.aspx";
Response.Redirect(returnUrl);
}
}
</pre>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-70079203395901842232013-04-25T11:55:00.002-07:002013-04-25T11:56:57.426-07:00Using a GUID as an EntityKey in Entity Framework 4<div dir="ltr" style="text-align: left;" trbidi="on">
Autogenerated GUID as primary key problem in Entity framework. Here is good solution for this problem.<br />
<div>
<br /></div>
<div>
<a href="http://leedumond.com/blog/using-a-guid-as-an-entitykey-in-entity-framework-4/">http://leedumond.com/blog/using-a-guid-as-an-entitykey-in-entity-framework-4/</a></div>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-48656547212019839102013-04-16T12:45:00.000-07:002013-04-24T10:56:55.168-07:00Ajax request to cross domain web service<div dir="ltr" style="text-align: left;" trbidi="on">
Here <b><a href="http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=wbp-3BJWsU8&format=json">http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=wbp-3BJWsU8&format=json</a></b> is an example URL<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<pre class="highlight">
$.ajax({
url: 'http://query.yahooapis.com/v1/public/yql',
data: {
q: "select * from json where url ='http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=wbp-3BJWsU8&format=json'",
format: "json"
},
dataType: "jsonp",
success: function (data) {
alert(JSON.stringify(data));
},
error: function (result) {
alert("Sorry no data found.");
}
});
</pre>
</div>Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-82822251273060780182013-04-14T10:24:00.002-07:002013-04-24T12:22:51.371-07:00Upload files using jquery fineuploader plugin in ASP.NET MVC<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px;">File uploading is one of the common tasks in web development.</span><br />
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px; padding: 0px 0px 10px;">
One of the best scripts for file uploading is <a href="https://github.com/valums/file-uploader" style="color: #186fd0;"><strong>valums/file-upoader</strong></a>.</div>
<div style="padding: 0px 0px 10px;">
<br />
<pre class="language-html">
<link href="@Url.Content("~/css/fileuploader.css")" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="@Url.Content("~/js/fileuploader.js")" type="text/javascript"></script>
<div id="file-uploader">
<noscript>
<p>Please enable JavaScript to use file uploader.</p>
</noscript>
</div>
<script type="text/javascript">
var uploader = new qq.FileUploader({
element: document.getElementById('file-uploader'),
action: '@Url.Action("upload")' // put here a path to your page to handle uploading
//,allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'] // user this if you want to upload only pictures
sizeLimit: 4000000, // max size, about 4MB
minSizeLimit: 0, // min size
});
</script>
</pre>
</div>
<h2 style="line-height: normal;">
Valums Ajax Upload Plugin Overview</h2>
<div style="padding: 0px 0px 10px;">
This plugin uses XHR for uploading multiple files with progress-bar in FF3.6+, Safari4+, Chrome and falls back to hidden iframe based upload in other browsers, providing good user experience everywhere.</div>
<h3 style="color: #aaaaaa; font-family: Arial, Georgia, 'Trebuchet MS'; font-size: 24px; font-weight: normal; letter-spacing: -2px; line-height: normal; margin: 20px 0px 0px; padding: 0px 0px 5px;">
Features</h3>
<ul style="line-height: normal; list-style: square; margin: 0px 0px 0px 20px; padding: 0px 0px 10px;">
<li style="list-style: square; margin: 0px 0px 0px 20px; padding: 0px 0px 5px;">multiple file select, progress-bar in FF, Chrome, Safari</li>
<li style="list-style: square; margin: 0px 0px 0px 20px; padding: 0px 0px 5px;">drag-and-drop file select in FF, Chrome</li>
<li style="list-style: square; margin: 0px 0px 0px 20px; padding: 0px 0px 5px;">uploads are cancellable</li>
<li style="list-style: square; margin: 0px 0px 0px 20px; padding: 0px 0px 5px;">no external dependencies</li>
<li style="list-style: square; margin: 0px 0px 0px 20px; padding: 0px 0px 5px;">doesn’t use Flash</li>
<li style="list-style: square; margin: 0px 0px 0px 20px; padding: 0px 0px 5px;">fully working with https</li>
<li style="list-style: square; margin: 0px 0px 0px 20px; padding: 0px 0px 5px;">keyboard support in FF, Chrome, Safari</li>
<li style="list-style: square; margin: 0px 0px 0px 20px; padding: 0px 0px 5px;">tested in IE7,8; Firefox 3,3.6,4; Safari4,5; Chrome; Opera10.60;</li>
</ul>
<div style="padding: 0px 0px 10px;">
<br /></div>
<h2 style="line-height: normal;">
Setup File Uploader plugin on ASP.NET MVC site</h2>
<div style="padding: 0px 0px 10px;">
Here is step-by-step instructions how to setup file-uploader script on your page on ASP.NET MVC site.</div>
<div style="padding: 0px 0px 10px;">
- Download the script from <a href="https://github.com/valums/file-uploader" style="color: #186fd0;">github</a>.</div>
<div style="padding: 0px 0px 10px;">
- Save files to the root of your project (or any folder you want). You need these three files:</div>
<div style="padding: 0px 0px 10px;">
/js/fileuploader.js</div>
<div style="padding: 0px 0px 10px;">
/css/fileuploader.css</div>
<div style="padding: 0px 0px 10px;">
/img/loading.gif</div>
<div style="padding: 0px 0px 10px;">
<br /></div>
<div style="padding: 0px 0px 10px;">
- Put the script on your page (view):</div>
<div style="padding: 0px 0px 10px;">
</div>
<br />
<span style="background-color: white; color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px;">- Create an ASP.NET MVC controller which will handle the file uploading and save the file to some location on the server:</span><br />
<pre class="highlight">public class HomeController : Controller
{
..
[HttpPost]
public ActionResult Upload(HttpPostedFileBase qqfile)
{
if (qqfile != null)
{
// this works for IE
var filename = Path.Combine(Server.MapPath("~/app_data"), Path.GetFileName(qqfile.FileName));
qqfile.SaveAs(filename);
return Json(new { success = true }, "text/html");
}
else
{
// this works for Firefox, Chrome
var filename = Request["qqfile"];
if (!string.IsNullOrEmpty(filename))
{
filename = Path.Combine(Server.MapPath("~/app_data"), Path.GetFileName(filename));
using (var output = System.IO.File.Create(filename))
{
Request.InputStream.CopyTo(output);
}
return Json(new { success = true });
}
}
return Json(new { success = false });
}
}
</pre>
<span style="background-color: white; color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px;"><br /></span>
<br />
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px; padding: 0px 0px 10px;">
Note that the controller action must return JsonResult.</div>
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px; padding: 0px 0px 10px;">
Also note that there are two different ways to handle uploads from IE and other (Firefox/Chrome) browsers. The issue here that IE uploads uses multipart-mime while other browsers use Octet-Stream. And Valums Ajax plugin sends an <code>application/octet-stream</code> instead of <code>multipart/form-data </code>which is what the default model binder can work with.</div>
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px; padding: 0px 0px 10px;">
<br /></div>
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px; padding: 0px 0px 10px;">
Fine more examples on <a href="https://github.com/valums/file-uploader" style="color: #186fd0;">github</a>.</div>
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px; padding: 0px 0px 10px;">
<br /></div>
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px; padding: 0px 0px 10px;">
Some discussions on stackoverflow about known issues:</div>
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px; padding: 0px 0px 10px;">
- <a href="http://stackoverflow.com/questions/4884920/mvc3-valums-ajax-file-upload" style="color: #186fd0;">http://stackoverflow.com/questions/4884920/mvc3-valums-ajax-file-upload</a></div>
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px; padding: 0px 0px 10px;">
- <a href="http://stackoverflow.com/questions/9882692/valums-file-uploader-doesnt-work-under-internet-explorer-9" style="color: #186fd0;">http://stackoverflow.com/questions/9882692/valums-file-uploader-doesnt-work-under-internet-explorer-9</a></div>
<div style="color: #333333; font-family: Helvetica, Arial, sans-serif, Tahoma, Verdana; font-size: 14px; line-height: 20px; padding: 0px 0px 10px;">
<a href="http://stackoverflow.com/questions/4888632/mvc-valums-ajax-uploader-ie-doesnt-send-the-stream-in-request-inputstream" style="color: #186fd0;">- http://stackoverflow.com/questions/4888632/mvc-valums-ajax-uploader-ie-doesnt-send-the-stream-in-request-inputstream</a></div>
</div>Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-73028483819995416632013-04-12T07:01:00.002-07:002013-04-24T12:29:13.620-07:00jquery ajax call to asmx webservice in asp.net<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #0b5394;"><b>jQuery script</b></span><br />
<span style="color: #0b5394;"><br /></span>
<span style="color: #0b5394;"><br /></span>
<br />
<pre class="highlight">$.ajax({
type: "POST",
url: "/WebServices/UserInfo.asmx/CheckAvailability",
data: "{ 'Title': '" + TitleName + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response);
},
error: function (data) {
alert(data);
}
});
</pre>
<span style="color: #0b5394;">Also made change in web config</span><br />
<span style="color: #0b5394;"><br /></span>
<br />
<pre class="highlight"><webservices>
<protocols>
<add name="HttpGet">
<add name="HttpPost">
</protocols>
</webservices>
</pre>
<br />
<span style="color: #0b5394;"><br /></span>
<br />
<br />
<table></table>
<table><tbody>
<tr><td class="webkit-line-content"><br /></td></tr>
<tr><td class="webkit-line-number"><br /></td><td class="webkit-line-content"><br /></td></tr>
<tr><td class="webkit-line-number"><br /></td><td class="webkit-line-content"><br /></td></tr>
<tr><td class="webkit-line-number"><br /></td><td class="webkit-line-content"><br /></td></tr>
<tr><td class="webkit-line-number"><br /></td><td class="webkit-line-content"><br /></td></tr>
<tr><td class="webkit-line-number"><br /></td><td class="webkit-line-content"><br /></td></tr>
<tr><td class="webkit-line-number"><br /></td><td class="webkit-line-content"></td></tr>
</tbody></table>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-29135404542831132402013-04-12T06:58:00.000-07:002013-04-24T11:12:26.483-07:00jquery ajax call to partial view in MVC3 <div dir="ltr" style="text-align: left;" trbidi="on">
<pre class="highlight">$.ajax({
type: "Get",
url: "/User/ResetPassword/",
success: function (data) {
$("#divId").html(data);
}
});
</pre>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-4498113970410970372012-12-15T09:35:00.005-08:002013-04-24T12:25:47.799-07:00scrollto - jQuery scroll To Element<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<b><span style="font-family: Verdana, sans-serif;">Here is jquery code</span></b><br />
<br />
<pre class="highlight">
<script>
function scrollToId(id) {
$("html, body").animate({ scrollTop: $('#'+id).offset().top }, 1000);
}
</script>
</pre>
<br />
<br />
<b>Here is HTML </b><br />
<br />
<br />
<pre class="highlight">
<ul class="menu">
<li><a onclick="scrollToId('Div1')">Example of a Link</a></li>
<li><a href="#Div2">The Active Link</a></li>
</ul>
</pre>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-3144496905912908932012-10-25T11:29:00.000-07:002012-10-25T11:29:12.826-07:00How to enable jQuery intellisense in Visual Studio<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="color: #555555; font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
There are two ways to enable jQuery intellisense in an external js file.</div>
<div class="MsoNormal" style="color: #555555; font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<br /></div>
<div class="MsoNormal" style="line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<b><span style="color: blue; font-family: Verdana, sans-serif;">First Method :</span></b></div>
<div class="MsoNormal" style="color: #555555; font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<br /></div>
<div class="MsoNormal" style="color: #555555; font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
To use the jQuery intellisense in an external javascript file, use the following configuration line on top of your javascript file.</div>
<div class="MsoNormal" style="color: #555555; font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<span lang="EN-IN"><o:p><br /></o:p></span></div>
<div class="MsoNormal" style="color: #555555; font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<span lang="EN-IN"><o:p><span style="color: brown;">/// <reference path="jquery-1.2.6.js"/></span></o:p></span></div>
<div class="MsoNormal" style="color: #555555; font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<span lang="EN-IN"><o:p><span style="color: brown;"><br /></span></o:p></span></div>
<div class="MsoNormal" style="color: #555555; font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<span lang="EN-IN"><o:p>The Path should take the original path where the jQuery file is placed in your project.</o:p></span></div>
<div class="MsoNormal" style="color: #555555; font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<b><span style="color: blue;"><br /></span></b></div>
<div class="MsoNormal" style="font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<b><span style="color: blue;">Second Method:</span></b></div>
<div class="MsoNormal" style="font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<span style="color: brown;"><br /></span></div>
<div class="MsoNormal" style="line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<span style="background-color: white; color: #666666; line-height: 31px;"><span style="font-family: Verdana, sans-serif;">Simply drag-n-drop the jQuery library from Solution Explorer to the opened external JavaScript file.</span></span></div>
<div class="MsoNormal" style="font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<span style="background-color: white; color: #666666; font-family: Georgia; font-size: 16px; line-height: 31px;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq08fNr-8Bdoa-Yhhbkwajjupr2I9_-_IcUeybO-5J-etpzmx_p-8LuWOoaCyNGKQjqDMB-A6vqaeTIOlOU6AodMpsxGScHSdkPBsLpxFwHlL9uIxITzmm5aZ4VrlikF3sCx4QPZbO-TKp/s1600/image11.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="196" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq08fNr-8Bdoa-Yhhbkwajjupr2I9_-_IcUeybO-5J-etpzmx_p-8LuWOoaCyNGKQjqDMB-A6vqaeTIOlOU6AodMpsxGScHSdkPBsLpxFwHlL9uIxITzmm5aZ4VrlikF3sCx4QPZbO-TKp/s400/image11.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">jQuery Intellisense in Visual Studio (1)</td></tr>
</tbody></table>
<div class="MsoNormal" style="font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<span style="background-color: white; color: #666666; font-family: Georgia; font-size: 16px; line-height: 31px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGasKA5dgvSB34VSJanoDB3vh90MFyUaswvFMXcRSEeZE2CgNoh4xabRbXTMx1_N5uRgtLpS24QFYuz_MQ7d00gzSCA2dr4mqe4c5mtgd1FK8TFhEcpv_W5BWMQkBZHXUy62sKQNhPbBY9/s1600/image12.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="205" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGasKA5dgvSB34VSJanoDB3vh90MFyUaswvFMXcRSEeZE2CgNoh4xabRbXTMx1_N5uRgtLpS24QFYuz_MQ7d00gzSCA2dr4mqe4c5mtgd1FK8TFhEcpv_W5BWMQkBZHXUy62sKQNhPbBY9/s400/image12.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">jQuery intellisense in Visual Studio (2)</td></tr>
</tbody></table>
<div class="MsoNormal" style="font-family: Verdana, Helvetica, sans-serif; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<span style="background-color: white; color: #666666; font-family: Georgia; font-size: 16px; line-height: 31px;"><br /></span></div>
<div class="MsoNormal" style="color: #555555; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<br /></div>
<div class="MsoNormal" style="color: #555555; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; line-height: 18px; margin: 0in 0in 0pt 1.5pt;">
<br /></div>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-20427839129276736102012-10-25T11:14:00.000-07:002012-10-25T11:30:43.590-07:00Scroll to an element smoothly using jQuery<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Verdana, sans-serif;"><span style="background-color: white; color: #444444;"><span style="line-height: 24px;">To get a smooth scrolling effect using one line of jQuery. You can use this small function of jQuery. It works especially well with<b> click.</b></span></span></span><br />
<span style="background-color: white; color: #444444; font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px;"><br /></span>
<br />
<pre class="default prettyprint prettyprinted" style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline;"><b style="background-color: white;"><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;"><html></span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;"><script</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px; vertical-align: baseline;">src</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px; vertical-align: baseline;">"http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">></script></span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;"><script></span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
$</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">document</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">).</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">ready</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">function</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(){</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
$</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="str" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">"#click"</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">).</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">click</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">function</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(){</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
$</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="str" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">'html, body'</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">).</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">animate</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">({</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
scrollTop</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> $</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="str" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">"#div1"</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">).</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">offset</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">().</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">top
</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">},</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">2000</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">);</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">});</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">});</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;"></script></span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;"><div</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px; vertical-align: baseline;">id</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px; vertical-align: baseline;">"div1"</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px; vertical-align: baseline;">style</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px; vertical-align: baseline;">"</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">height</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">1000px</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> width </span><span class="lit" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">100px</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px; vertical-align: baseline;">"</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">></span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
test
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;"></div></span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;"><br/></span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;"><div</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px; vertical-align: baseline;">id</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px; vertical-align: baseline;">"div2"</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px; vertical-align: baseline;">style</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px; vertical-align: baseline;">"</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">height</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">1000px</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> width </span><span class="lit" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">100px</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px; vertical-align: baseline;">"</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">></span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
test 2
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;"></div></span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;"><button</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px; vertical-align: baseline;">id</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px; vertical-align: baseline;">"click"</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">></span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">click me</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;"></button></span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;"></html></span></b></code></pre>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-81585037939475701552012-09-23T13:10:00.001-07:002012-09-23T13:11:00.346-07:00What is .NET <div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial, Helvetica, sans-serif;">.NET is a software framework developed by Microsoft Corporation to build different types of application.</span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">We can build following types of application using .net framework</span><br />
<ul style="text-align: left;">
<li><span style="font-family: Arial, Helvetica, sans-serif;">Console Application</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">Windows Applications</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">Web Applications</span></li>
</ul>
<span style="font-family: Arial, Helvetica, sans-serif;">.NET framework support multiple programming languages to develop these applications.</span><br />
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Here is a list of programming languages supported by .NET framework.</span></div>
<div>
<ul style="text-align: left;">
<li><span style="font-family: Arial, Helvetica, sans-serif;">C# ( C Sharp)</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">VB (visual basic)</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">F# (F Sharp)</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">etc.</span></li>
</ul>
</div>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-30308299809395049102012-09-20T12:15:00.001-07:002012-09-20T12:24:04.736-07:00How to use jQuery in ASP.NET<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
</div>
<div style="text-align: justify;">
<span style="font-family: Arial, Helvetica, sans-serif;">In this tutorial, We will learn how to use jQuery with ASP.NET.</span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<div style="text-align: justify;">
<span style="font-family: Arial, Helvetica, sans-serif;">For this your have to do some simple tasks.</span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span><span style="font-family: Arial, Helvetica, sans-serif;"><div style="text-align: justify;">
<ul>
<li>First Add new website in <b>visual studio</b> and save it on your computer's File system.</li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">Now Open your website and Create a new page or use Default.aspx page (which is created automatically for you by </span><span style="font-family: Arial, Helvetica, sans-serif;">Visual Studio.) </span></li>
<li>Now, We are going to use jQuery in our website so we have to import some jQuery files in our webpage. </li>
<li><b>Visual studio 2010</b><span style="font-family: Arial, Helvetica, sans-serif;"><b> </b>already have these files for you in<b> script folder</b>. You can just drag and drop these files to your webpage's head section or manually put them. </span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">We will use </span><span style="font-family: Arial, Helvetica, sans-serif;"><b>jquery-1.4.1.js</b> here ( You can also use other version of jquery file). </span></li>
<li>After adding these files Your page will look like this.</li>
</ul>
</div>
</span>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIeSCHTMgOgHu4OTPoQ53xgQvz-CXqXg3rfRZ0uhJ1VXUcy7QkeYk95ITAhxi5tL3ZKICeKhJqcwkZ8j9PtdEZHmy3VtIOgxvAA_2GaswL-wsAjEgTRCO2NBHFkqiOfEvz6YbvqIkP-H4y/s1600/Untitled.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIeSCHTMgOgHu4OTPoQ53xgQvz-CXqXg3rfRZ0uhJ1VXUcy7QkeYk95ITAhxi5tL3ZKICeKhJqcwkZ8j9PtdEZHmy3VtIOgxvAA_2GaswL-wsAjEgTRCO2NBHFkqiOfEvz6YbvqIkP-H4y/s640/Untitled.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
<span style="font-family: Arial, Helvetica, sans-serif;">Now, In head section we will write jQuery code in script tag. </span><span style="font-family: Arial, Helvetica, sans-serif;">Here, A simple code of jQuery which changes Text of a </span><b style="font-family: Arial, Helvetica, sans-serif;">Label </b><span style="font-family: Arial, Helvetica, sans-serif;">on a </span><b style="font-family: Arial, Helvetica, sans-serif;">HTML Button's</b><span style="font-family: Arial, Helvetica, sans-serif;"> click</span></div>
</div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQzKpVZyADGKHJMqRCxj0HBLs_TcDfaqTBaPUSqKDUCUa6hpm4PEHVnAah9e3x18AZc9pkrLzgt0TE3PuJ0YK_ytNtlQxA41cqmVy0uqXmzENU7XtLh9I9LYYg8jKAWN95QKGj0846jDsR/s1600/Untitled.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="387" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQzKpVZyADGKHJMqRCxj0HBLs_TcDfaqTBaPUSqKDUCUa6hpm4PEHVnAah9e3x18AZc9pkrLzgt0TE3PuJ0YK_ytNtlQxA41cqmVy0uqXmzENU7XtLh9I9LYYg8jKAWN95QKGj0846jDsR/s640/Untitled.png" width="640" /></a></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Explanation : </b>The Explanation is quite simple. When our webpage gets ready, a function is called which binds<b> button1's</b> click event to a function (event handler for click event ) and when </span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"> button is clicked, a function is called (or we can say an event is handled) which selects </span><b style="font-family: Arial, Helvetica, sans-serif;">label1</b><span style="font-family: Arial, Helvetica, sans-serif;"> and changes it's<b> </b></span><span style="font-family: Arial, Helvetica, sans-serif;"><b>text </b>property. That's All.</span>
The main advantage of jQuery is that it works the whole work without any post back at <span style="font-family: Arial, Helvetica, sans-serif;">client-side. It was the very basic example of jQuery. Further i will post more useful examples.</span>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-85792289474203458312012-09-19T13:27:00.003-07:002012-09-20T12:22:01.183-07:00Difference between jquery.min.js and jquery.js ?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="line-height: 18px;">Both support the same functions. </span></span><span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="line-height: 18px;"><b>jquery.min.js</b> is a compressed version of <b>jquery.js</b> (whitespaces and comments stripped out, shorter variable names, ...) in order to preserve bandwidth. </span></span><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px;">In terms of functionality they are absolutely the same. It is recommended to use this compressed version in production environment.</span></div>
<br />
<span style="color: #3d85c6; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: x-small; line-height: 18px;">Source</span><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: x-small; line-height: 18px;"> :</span><span style="color: orange; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: x-small; line-height: 18px;"> <a href="http://stackoverflow.com/questions/3475024/whats-the-difference-between-jquery-js-and-jquery-min-js"><span style="color: orange;">Stackoverflow</span></a></span></div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0tag:blogger.com,1999:blog-5581752652206236282.post-76142335973070651552012-07-22T06:42:00.001-07:002012-09-19T13:41:23.109-07:00What are Sealed Classes in C#?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealedclass is specified as the base class of another class. (A sealed class cannot also be an abstract class)</span></div>
</div>
Ankush Jainhttp://www.blogger.com/profile/03444548441230900532noreply@blogger.com0