Tuesday, December 27, 2011

Microsoft Zune Sign In Issue

After checking the location on windows live ID and checking my PC's location as below image
But then also it is showing below error.



Does anyone has any idea about how to solve above specified error in Microsoft Zune while sign in?

Any help will be very much appreciated.

Sunday, March 13, 2011

Nice Poem

દરેક ખુશી છે અહિ લોકો પાસે, પણ હસવા માટે સમય નથી
દિવસ-રાત દોડતી દુનિયા મા, જિંદગી માટે પણ સમય નથી

મા ના હાલરડા નો અહેસાસ છે, પણ મા ની મમતા માટે સમય નથી
બધા સંબંધો તો મરી ગયા જાણે, પણ તેમને દફનાવવાનો સમય નથી

બધા નામ મોબાઈલ મા છે પણ, મિત્રતા માટે સમય નથી
પાર્કા ઓ ની શુ વાત કરવી, પોતના માટે પણ સમય નથી

આંખો મા છે ઊંઘ ઘણીયે, પણ સુવા માટે સમય નથી
દિલ છે ગમો થી ભરેલુ, પણ રોવા માટે સમય નથી

પૈસા ની દોડ મા એવા દોડ્યા, કે થાકવા નો પણ સમય નથી
પારકા અહેસાનો ની શી કદર કેરીએ, જ્યા પોતાના સપના ની જ કદર નથી

તુ જ કહે મને એ, શી થશે આ જિંદગી નુ,,,,,
દરેક પળે મરવા વાળા ને, જિવવા માટે પણ સમય નથી..........
Thanks

Tuesday, September 2, 2008

Crafting Lightweight Page Templates with css

by Nirav Mehta


Giving your web application a consistent look and feel is a task of paramount importance. Yet, templating in ASP.NET has been complicated, to say the least. Learn how you can craft lightweight, efficient page templates with CSS.
Unfortunately, building page templates in ASP.NET has never been easy. There are several solutions to this tricky problem, but they all either involve complex inheritance with some page build-out mechanism (which is what I utilize on this site), or they put to work HttpHandlers and HttpModules and load server controls on the fly. All this is beyond the grasp of a novice developer.

There's an effective approach to building lightweight page templates. This approach requires no advanced ASP.NET skills. I didn't invent it. In fact, I think I first saw Doug Bowman use it, and then read about it in Dan Cederholm's book Web Standards Solutions. I know Mark Pilgrim has used it, and so has Ian Hickson.

By the time we're done you'll be surprised ASP.NET has very little to do with it.

"body tag" Styling
The idea is quite simple: we can assign the good ol' body tag element an id and a class. Next, we build a generic page template and write CSS rules that cater to each body style individually.

An example will help clarify my point. Let's create a bare-bones web log for a fictional personage, Mr. Hugh Jass. We'll create three simple pages: Home, Contact and About and fill them with Lorem Ipsum text. I've used my own web form template generator to create each one. The "blog" has no artistic value; I've thrown in just enough CSS to back up my point.

The structure of each page is the same (since we're developing a template):

<body>
<div id="masthead">...</div>
<div id="leftcol">...</div>
<div id="rightcol">...</div>
<div id="content">...</div>
<div id="footer">...</div>
</body>
You see a header (masthead), footer and three columns. We'll establish up front this much: some pages will show all three columns, others—two. We'll remember to assign each <body> element a corresponding class.

<body class="twocolumns">
...
</body>Or

<body class="threecolumns">
...
</body>On a three-column page I float the left and right columns and squeeze content in between:

#content {
background: #eee;
padding: 0 2%;
margin-left: 25%;
}

#leftcol {
width: 20%;
float: left;
padding: 0 2%;
}

body.threecolumns #rightcol {
width: 20%;
float: right;
padding: 0 2%;
}

body.threecolumns #content {
margin-right: 25%;
}The left column will always be there (in our imaginary blog). Both columns are given a 20% width with content taking up the rest. Note the body.threecolumns #content selector. The entire rule is applied to #content within a <body> of class threecolumns:

<body class="threecolumns">
...
<div id="content">...</div>
...
</body>The Home page of our blog has all three columns.

On we go to a two-column page. The About page is built this way. We simply use the CSS display property to hide it and adjust content to stretch and take the rest of the space:

body.twocolumns #content {
margin-right: 2%;
}

body#contact #footer {
display: none;
}The Contact page is a modification of a two-column page. It shows no footer. By this I wanted to demonstrate that in addition to assigning <body> a class you can also take advantage of its id:

<body id="contact" class="twocolumns">
...
</body>The CSS rule that hides the footer on this page only (!) is shown below.

body#contact #footer {
display: none;
}Done and done.

class or id?
If you research this subject on the web you'll see different opinions on whether to assign <body> an id or a class. I'll throw my opinion into the mix.

I give <body> an id only if I want to make a modification that is catered to that page only. If a modification is of a generic kind (such as hiding a column, which is done on a number of pages) a class is more appropriate. You should choose whatever works better for each project and go with it. There's no crime in using only classes or ids.

visibility or display?
Another tricky question. The CSS display: none declaration generates no element box, i.e. the hidden element "disappears" and takes no space. On the other hand, visibility: hidden does generate an element box and takes space, even though you don't see the element itself.

Since we needed to hide the right column completely—and couldn't afford having a gaping hole that visibility produces—I chose display.

Spicing Up the Template
If you download the code you'll see ASP.NET really played no part here! It's all HTML and CSS. You can take it from here and wrap the masthead into a user control, for example. Have it produce a consistent header with a logo and navigation. You can wrap the footer into a user control as well. Finally, you may have other static content or database-driven custom server controls to do heavy lifting. Plug them in where you see fit.

Conclusion
Templating with CSS is an approach that is easy to master even by novice ASP.NET developers. Of course, it has its own shortcomings, but so does every templating solution out there. I hope I taught you a new way to leverage (such a popular term these days) the power of CSS!

by Nirav Mehta



Discuss
Liked it? Hated it? Discuss this article

Silverlight Applications Offline

by Nirav Mehta


This has always been an issue when we talk about Silverlight and so much as been said about it, and so let’s look at the options.

First of all we need to think that Silverlight was not built to be a technology to deliver Occasionally Online applications, it was built to deliver RIA, and so it was made to use Online and not Offline. Is this a problem?

Secondly, Silverlight is a subset of Windows Presentation Foundation (WPF), and so my question is: Do we really need the Occasionally Online approach in Silverlight or do we need to be able to run everything we do in Silverlight in WPF also?

And so my thoughts about my own questions are:

There’s no problem with Silverlight not having been thought in terms of needing the Occasionally Online approach because this is the purpose of WPF, but it must be enhanced with something like the Occasionally Offline approach, because sometimes our Internet connections go down, for several different reasons, and we don’t want to lose all our work done in the Silverlight apps. And if we think that Silverlight 2.0 was built to bring the ability not only for the islands of richness, that was brought by the version 1.0, but also to provide a platform to build Line-Of-Business Applications this will take a lot more importance.

Still about Silverlight having the need to support the Occasionally Online approach I would say that this isn’t really a must have because this is really an Architectural choice to be made during the product planing, and so if we need a Occasionally Online approach we use WPF, and if we need an Online approach we’ll use Silverlight.

OK this is nice but there’s one important aspect that we are forgetting and that is that a product will evolve and suddenly it can turn to need an Occasionally Online approach and so, what will we do? Will we need to build the application again? Of course not, this is where the interaction between WPF and Silverlight needs to appear, because it’s needed that all the features and even controls that work in Silverlight work well in WPF, because this is how real subset frameworks work, and is this now true in Silvelight and WPF? The answer is not everything works, but it’s being worked on.

So a lot still needs to be done in this two awesome technologies that bring great User Experience for applications, but we need to think also that they are relatively new because WPF with the release of .NET 3.5 SP1 just had it’s Third Major Release, and Silvelight is only going for it’s Second. This being said a lot should be expected in both this areas.

In terms of what choices do we have today for making Silvelight a Desktop application / Occasionally Online Applications, they are the following:

Pack it with a lightweight Web Server like Cassini Web Server
Pack it with a custom build Windows Service that will serve the Http Requests needed by the Silverlight App. This seams to me a lot harder because to much as to be done.
Transform it to a WPF like Application. Use this Desklighter tool that will convert your Silverlight App into a Desktop App.
This is a very interesting topic and I would like to hear your thoughts about this subject, so feel free to comment.

by Nirav Mehta

Monday, September 1, 2008

Important .NET Interview Questions & Answers Part - 2

by Nirav Mehta


26. Should validation (did the user enter a real date) occur server-side or client-side? Why?


Client-side validation because there is no need to request a server side date when you could obtain a date from the client machine.

27. What are ASP.NET Web Forms? How is this technology different than what is available though ASP?


Web Forms are the heart and soul of ASP.NET. Web Forms are the User Interface (UI) elements that give your Web applications their look and feel. Web Forms are similar to Windows Forms in that they provide properties, methods, and events for the controls that are placed onto them. However, these UI elements render themselves in the appropriate markup language required by the request, e.g. HTML. If you use Microsoft Visual Studio .NET, you will also get the familiar drag-and-drop interface used to create your UI for your Web application.

28. What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other?


In earlier versions of IIS, if we wanted to send a user to a new Web page, the only option we had was Response.Redirect. While this method does accomplish our goal, it has several important drawbacks. The biggest problem is that this method causes each page to be treated as a separate transaction. Besides making it difficult to maintain your transactional integrity, Response.Redirect introduces some additional headaches. First, it prevents good encapsulation of code. Second, you lose access to all of the properties in the Request object. Sure, there are workarounds, but they're difficult. Finally, Response.Redirect necessitates a round trip to the client, which, on high-volume sites, causes scalability problems.
As you might suspect, Server.Transfer fixes all of these problems. It does this by performing the transfer on the server without requiring a roundtrip to the client.

29. How can you provide an alternating color scheme in a Repeater control?


AlternatingItemTemplate Like the ItemTemplate element, but rendered for every other row (alternating items) in the Repeater control. You can specify a different appearance for the AlternatingItemTemplate element by setting its style properties.

30. Which template must you provide, in order to display data in a Repeater control?


ItemTemplate

31. What event handlers can I include in Global.asax?


Application_Start,Application_End, Application_AcquireRequestState, Application_AuthenticateRequest, Application_AuthorizeRequest, Application_BeginRequest, Application_Disposed, Application_EndRequest, Application_Error, Application_PostRequestHandlerExecute, Application_PreRequestHandlerExecute,
Application_PreSendRequestContent, Application_PreSendRequestHeaders, Application_ReleaseRequestState, Application_ResolveRequestCache, Application_UpdateRequestCache, Session_Start,Session_End
You can optionally include "On" in any of method names. For example, you can name a BeginRequest event handler.Application_BeginRequest or Application_OnBeginRequest.You can also include event handlers in Global.asax for events fired by custom HTTP modules.Note that not all of the event handlers make sense for Web Services (they're designed for ASP.NET applications in general, whereas .NET XML Web Services are specialized instances of an ASP.NET app). For example, the Application_AuthenticateRequest and Application_AuthorizeRequest events are designed to be used with ASP.NET Forms authentication.

32. What is different b/w webconfig.xml & Machineconfig.xml


Web.config & machine.config both are configuration files.Web.config contains settings specific to an application where as machine.config contains settings to a computer. The Configuration system first searches settings in machine.config file & then looks in application configuration files.Web.config, can appear in multiple directories on an ASP.NET Web application server. Each Web.config file applies configuration settings to its own directory and all child directories below it. There is only Machine.config file on a web server.

If I'm developing an application that must accomodate multiple security levels though secure login and my ASP.NET web appplication is spanned across three web-servers (using round-robbin load balancing) what would be the best approach to maintain login-in state for the users?
Use the state server or store the state in the database. This can be easily done through simple setting change in the web.config.
StateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1; user id=sa; password="
cookieless="false"
timeout="30"
/>

You can specify mode as “stateserver” or “sqlserver”.

Where would you use an iHTTPModule, and what are the limitations of any approach you might take in implementing one
"One of ASP.NET's most useful features is the extensibility of the HTTP pipeline, the path that data takes between client and server. You can use them to extend your ASP.NET applications by adding pre- and post-processing to each HTTP request coming into your application. For example, if you wanted custom authentication facilities for your application, the best technique would be to intercept the request when it comes in and process the request in a custom HTTP module.

33. How do you turn off cookies for one page in your site?


Since no Page Level directive is present, I am afraid that cant be done.

34. How do you create a permanent cookie?


Permanent cookies are available until a specified expiration date, and are stored on the hard disk.So Set the 'Expires' property any value greater than DataTime.MinValue with respect to the current datetime. If u want the cookie which never expires set its Expires property equal to DateTime.maxValue.

35. Which method do you use to redirect the user to another page without performing a round trip to the client?


Server.Transfer and Server.Execute

36. What property do you have to set to tell the grid which page to go to when using the Pager object?


CurrentPageIndex

37. Should validation (did the user enter a real date) occur server-side or client-side? Why?


It should occur both at client-side and Server side.By using expression validator control with the specified expression ie.. the regular expression provides the facility of only validatating the date specified is in the correct format or not. But for checking the date where it is the real data or not should be done at the server side, by getting the system date ranges and checking the date whether it is in between that range or not.

38. What does the "EnableViewState" property do? Why would I want it on or off?


Enable ViewState turns on the automatic state management feature that enables server controls to re-populate their values on a round trip without requiring you to write any code. This feature is not free however, since the state of a control is passed to and from the server in a hidden form field. You should be aware of when ViewState is helping you and when it is not. For example, if you are binding a control to data on every round trip, then you do not need the control to maintain it's view state, since you will wipe out any re-populated data in any case. ViewState is enabled for all server controls by default. To disable it, set the EnableViewState property of the control to false.

39. What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other?


Server.Transfer() : client is shown as it is on the requesting page only, but the all the content is of the requested page. Data can be persist accros the pages using Context.Item collection, which is one of the best way to transfer data from one page to another keeping the page state alive.

Response.Dedirect() :client know the physical location (page name and query string as well). Context.Items loses the persisitance when nevigate to destination page. In earlier versions of IIS, if we wanted to send a user to a new Web page, the only option we had was Response.Redirect. While this method does accomplish our goal, it has several important drawbacks. The biggest problem is that this method causes each page to be treated as a separate transaction. Besides making it difficult to maintain your transactional integrity, Response.Redirect introduces some additional headaches. First, it prevents good encapsulation of code. Second, you lose access to all of the properties in the Request object. Sure, there are workarounds, but they're difficult. Finally, Response.Redirect necessitates a round trip to the client, which, on high-volume sites, causes scalability problems. As you might suspect, Server.Transfer fixes all of these problems. It does this by performing the transfer on the server without requiring a roundtrip to the client.


40. Can you give an example of when it would be appropriate to use a web service as opposed to a non-serviced .NET component?



* Communicating through a Firewall When building a distributed application with 100s/1000s of users spread over multiple locations, there is always the problem of communicating between client and server because of firewalls and proxy servers. Exposing your middle tier components as Web Services and invoking the directly from a Windows UI is a very valid option.
* Application Integration When integrating applications written in various languages and running on disparate systems. Or even applications running on the same platform that have been written by separate vendors.
* Business-to-Business Integration This is an enabler for B2B intergtation which allows one to expose vital business processes to authorized supplier and customers. An example would be exposing electronic ordering and invoicing, allowing customers to send you purchase orders and suppliers to send you invoices electronically.
* Software Reuse This takes place at multiple levels. Code Reuse at the Source code level or binary componet-based resuse. The limiting factor here is that you can reuse the code but not the data behind it. Webservice overcome this limitation. A scenario could be when you are building an app that aggregates the functionality of serveral other Applicatons. Each of these functions could be performed by individual apps, but there is value in perhaps combining the the multiple apps to present a unifiend view in a Portal or Intranet.
* When not to use Web Services: Single machine Applicatons When the apps are running on the same machine and need to communicate with each other use a native API. You also have the options of using component technologies such as COM or .NET Componets as there is very little overhead.
* Homogeneous Applications on a LAN If you have Win32 or Winforms apps that want to communicate to their server counterpart. It is much more efficient to use DCOM in the case of Win32 apps and .NET Remoting in the case of .NET Apps

41. Can you give an example of what might be best suited to place in the Application_Start and Session_Start subroutines?


The Application_Start event is guaranteed to occur only once throughout the lifetime of the application. It's a good place to initialize global variables. For example, you might want to retrieve a list of products from a database table and place the list in application state or the Cache object. SessionStateModule exposes both Session_Start and Session_End events.

41. What are the advantages and disadvantages of viewstate?


The primary advantages of the ViewState feature in ASP.NET are:

1. Simplicity. There is no need to write possibly complex code to store form data between page submissions.
2. Flexibility. It is possible to enable, configure, and disable ViewState on a control-by-control basis, choosing to persist the values of some fields but not others.

There are, however a few disadvantages that are worth pointing out:

1. Does not track across pages. ViewState information does not automatically transfer from page to page. With the session
approach, values can be stored in the session and accessed from other pages. This is not possible with ViewState, so storing
data into the session must be done explicitly.

2. ViewState is not suitable for transferring data for back-end systems. That is, data still has to be transferred to the back
end using some form of data object.

42. Describe session handling in a webfarm, how does it work and what are the limits?


ASP.NET Session supports storing of session data in 3 ways, i] in In-Process ( in the same memory that ASP.NET uses) , ii] out-of-process using Windows NT Service )in separate memory from ASP.NET ) or iii] in SQL Server (persistent storage). Both the Windows Service and SQL Server solution support a webfarm scenario where all the web-servers can be configured to share common session state store.

1. Windows Service :
We can start this service by Start Control Panel Administrative Tools Services . In that we service names ASP.NET State Service. We can start or stop service by manually or configure to start automatically. Then we have to configure our web.config file



mode = “StateServer”
stateConnectionString = “tcpip=127.0.0.1:42424”
stateNetworkTimeout = “10”
sqlConnectionString=”data source = 127.0.0.1; uid=sa;pwd=”
cookieless =”Flase”
timeout= “20” />



Here ASP.Net Session is directed to use Windows Service for state management on local server (address : 127.0.0.1 is TCP/IP loop-back address). The default port is 42424. we can configure to any port but for that we have to manually edit the registry.
Follow these simple steps
- In a webfarm make sure you have the same config file in all your web servers.
- Also make sure your objects are serializable.
- For session state to be maintained across different web servers in the webfarm, the application path of the web-site in the IIS Metabase should be identical in all the web-servers in the webfarm.

43. What are the new Data Controls in Asp.net 2.0?



Data access in ASP.NET 2.0 can be accomplished completely declaratively (no code) using the new data-bound and data source controls. There are new data source controls to represent different data backends such as SQL database, business objects, and XML, and there are new data-bound controls for rendering common UI for data, such as gridview, detailsview, and formview.

44. What are the new Navigation Controls in Asp.net 2.0?



The navigation controls provide common UI for navigating between pages in your site, such as treeview, menu, and sitemappath. These controls use the site navigation service in ASP.NET 2.0 to retrieve the custom structure you have defined for your site.

45. What are the new Login Controlsin Asp.net 2.0?



The new login controls provide the building blocks to add authentication and authorization-based UI to your site, such as login forms, create user forms, password retrieval, and custom UI for logged in users or roles. These controls use the built-in membership and role services in ASP.NET 2.0 to interact with the user and role information defined for your site.

46. What are the new Web Part Controls in Asp.net 2.0 ?



Web parts are an exciting new family of controls that enable you to add rich, personalized content and layout to your site, as well as the ability to edit that content and layout directly from your application pages. These controls rely on the personalization services in ASP.NET 2.0 to provide a unique experience for each user in your application.

47. What are Master Pages?



This feature provides the ability to define common structure and interface elements for your site, such as a page header, footer, or navigation bar, in a common location called a "master page", to be shared by many pages in your site. In one simple place you can control the look, feel, and much of functionality for an entire Web site. This improves the maintainability of your site and avoids unnecessary duplication of code for shared site structure or behavior.

48. What are Themes and Skins in 2.0, explain usgae scenario?


The themes and skins features in ASP.NET 2.0 allow for easy customization of your site's look-and-feel. You can define style information in a common location called a "theme", and apply that style information globally to pages or controls in your site. Like Master Pages, this improves the maintainability of your site and avoid unnecessary duplication of code for shared styles

49. When was .NET announced?



Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and delegates were given CDs containing a pre-release version of the .NET framework/SDK and Visual Studio.NET.

50. When was the first version of .NET released?


The final version of the 1.0 SDK and runtime was made publicly available around 6pm PST on 15-Jan-2002. At the same time, the final version of Visual Studio.NET was made available to MSDN subscribers.

by Nirav Mehta

Important .NET Interview Questions & Answers Part - 1

by Nirav Mehta


1. What is view state and use of it?


The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested for the first time versus when the form is posted (sent to the server), which allows you to program accordingly.

2. What are user controls and custom controls?


Custom controls:
A control authored by a user or a third-party software vendor that does not belong to the .NET Framework class library. This is a generic term that includes user controls. A custom server control is used in Web Forms (ASP.NET pages). A custom client control is used in Windows Forms applications.

User Controls:
In ASP.NET: A user-authored server control that enables an ASP.NET page to be re-used as a server control. An ASP.NET user control is authored declaratively and persisted as a text file with an .ascx extension. The ASP.NET page framework compiles a user control on the fly to a class that derives from the System.Web.UI.UserControl class.

3. What are the validation controls?


A set of server controls included with ASP.NET that test user input in HTML and Web server controls for programmer-defined requirements. Validation controls perform input checking in server code. If the user is working with a browser that supports DHTML, the validation controls can also perform validation using client script.

4. What's the difference between Response.Write() andResponse.Output.Write()?


The latter one allows you to write formattedoutput.

5. What methods are fired during the page load? Init()


When the page is instantiated, Load() - when the page is loaded into server memory,PreRender () - the brief moment before the page is displayed to the user as HTML, Unload() - when page finishes loading.

6. Where does the Web page belong in the .NET Framework class hierarchy?


System.Web.UI.Page

7. Where do you store the information about the user's locale?


System.Web.UI.Page.Culture

8. What's the difference between Codebehind="MyCode.aspx.cs" and Src="MyCode.aspx.cs"?


CodeBehind is relevant to Visual Studio.NET only.

9. What's a bubbled event?


When you have a complex control, likeDataGrid, writing an event processing routine for each object (cell, button,row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.
Suppose you want a certain ASP.NET function executed on MouseOver over a certain button.

10. Where do you add an event handler?


It's the Attributesproperty, the Add function inside that property.
e.g. btnSubmit.Attributes.Add("onMouseOver","someClientCode();")

11. What data type does the RangeValidator control support?


Integer,String and Date.

12. What are the different types of caching?


Caching is a technique widely used in computing to increase performance by keeping frequently accessed or expensive data in memory. In context of web application, caching is used to retain the pages or data across HTTP requests and reuse them without the expense of recreating them.ASP.NET has 3 kinds of caching strategiesOutput CachingFragment CachingData

CachingOutput Caching: Caches the dynamic output generated by a request. Some times it is useful to cache the output of a website even for a minute, which will result in a better performance. For caching the whole page the page should have OutputCache directive.<%@ OutputCache Duration="60" VaryByParam="state" %>

Fragment Caching: Caches the portion of the page generated by the request. Some times it is not practical to cache the entire page, in such cases we can cache a portion of page<%@ OutputCache Duration="120" VaryByParam="CategoryID;SelectedID"%>

Data Caching: Caches the objects programmatically. For data caching asp.net provides a cache object for eg: cache["States"] = dsStates;

13. What do you mean by authentication and authorization?


Authentication is the process of validating a user on the credentials (username and password) and authorization performs after authentication. After Authentication a user will be verified for performing the various tasks, It access is limited it is known as authorization.

14. What are different types of directives in .NET?


@Page: Defines page-specific attributes used by the ASP.NET page parser and compiler. Can be included only in .aspx files <%@ Page AspCompat="TRUE" language="C#" %>
@Control:Defines control-specific attributes used by the ASP.NET page parser and compiler. Can be included only in .ascx files. <%@ Control Language="VB" EnableViewState="false" %>
@Import: Explicitly imports a namespace into a page or user control. The Import directive cannot have more than one namespace attribute. To import multiple namespaces, use multiple @Import directives. <% @ Import Namespace="System.web" %>
@Implements: Indicates that the current page or user control implements the specified .NET framework interface.<%@ Implements Interface="System.Web.UI.IPostBackEventHandler" %>
@Register: Associates aliases with namespaces and class names for concise notation in custom server control syntax.<%@ Register Tagprefix="Acme" Tagname="AdRotator" Src="AdRotator.ascx" %>
@Assembly: Links an assembly to the current page during compilation, making all the assembly's classes and interfaces available for use on the page. <%@ Assembly Name="MyAssembly" %><%@ Assembly Src="MySource.vb" %>
@OutputCache: Declaratively controls the output caching policies of an ASP.NET page or a user control contained in a page<%@ OutputCache Duration="#ofseconds" Location="Any Client Downstream Server None" Shared="True False" VaryByControl="controlname" VaryByCustom="browser customstring" VaryByHeader="headers" VaryByParam="parametername" %>
@Reference: Declaratively indicates that another user control or page source file should be dynamically compiled and linked against the page in which this directive is declared.

15. How do I debug an ASP.NET application that wasn't written with Visual Studio.NET and that doesn't use code-behind?


Start the DbgClr debugger that comes with the .NET Framework SDK, open the file containing the code you want to debug, and set your breakpoints. Start the ASP.NET application. Go back to DbgClr, choose Debug Processes from the Tools menu, and select aspnet_wp.exe from the list of processes. (If aspnet_wp.exe doesn't appear in the list,check the "Show system processes" box.) Click the Attach button to attach to aspnet_wp.exe and begin debugging.
Be sure to enable debugging in the ASPX file before debugging it with DbgClr. You can enable tell ASP.NET to build debug executables by placing a
<%@ Page Debug="true" %> statement at the top of an ASPX file or a statement in a Web.config file.

16. Can a user browsing my Web site read my Web.config or Global.asax files?


No. The section of Machine.config, which holds the master configuration settings for ASP.NET, contains entries that map ASAX files, CONFIG files, and selected other file types to an HTTP handler named HttpForbiddenHandler, which fails attempts to retrieve the associated file. You can modify it by editing Machine.config or including an section in a local Web.config file.

17. What's the difference between Page.RegisterClientScriptBlock and Page.RegisterStartupScript?


RegisterClientScriptBlock is for returning blocks of client-side script containing functions. RegisterStartupScript is for returning blocks of client-script not packaged in functions-in other words, code that's to execute when the page is loaded. The latter positions script blocks near the end of the document so elements on the page that the script interacts are loaded before the script runs.<%@ Reference Control="MyControl.ascx" %>

18. Is it necessary to lock application state before accessing it?


Only if you're performing a multistep update and want the update to be treated as an atomic operation. Here's an example:
Application.Lock ();
Application["ItemsSold"] = (int) Application["ItemsSold"] + 1;
Application["ItemsLeft"] = (int) Application["ItemsLeft"] - 1;
Application.UnLock ();
By locking application state before updating it and unlocking it afterwards, you ensure that another request being processed on another thread doesn't read application state at exactly the wrong time and see an inconsistent view of it. If I update session state, should I lock it, too? Are concurrent accesses by multiple requests executing on multiple threads a concern with session state?
Concurrent accesses aren't an issue with session state, for two reasons. One, it's unlikely that two requests from the same user will overlap. Two, if they do overlap, ASP.NET locks down session state during request processing so that two threads can't touch it at once. Session state is locked down when the HttpApplication instance that's processing the request fires an AcquireRequestState event and unlocked when it fires a ReleaseRequestState event.

19. Do ASP.NET forms authentication cookies provide any protection against replay attacks? Do they, for example, include the client's IP address or anything else that would distinguish the real client from an attacker?


No. If an authentication cookie is stolen, it can be used by an attacker. It's up to you to prevent this from happening by using an encrypted communications channel (HTTPS). Authentication cookies issued as session cookies, do, however,include a time-out valid that limits their lifetime. So a stolen session cookie can only be used in replay attacks as long as the ticket inside the cookie is valid. The default time-out interval is 30 minutes.You can change that by modifying the timeout attribute accompanying the element in Machine.config or a local Web.config file. Persistent authentication cookies do not time-out and therefore are a more serious security threat if stolen.

20. How do I send e-mail from an ASP.NET application?



MailMessage message = new MailMessage ();
message.From = ;
message.To = ;
message.Subject = "Scheduled Power Outage";
message.Body = "Our servers will be down tonight.";
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send (message);

MailMessage and SmtpMail are classes defined in the .NET Framework Class Library's System.Web.Mail namespace. Due to a security change made to ASP.NET just before it shipped, you need to set SmtpMail's SmtpServer property to "localhost" even though "localhost" is the default. In addition, you must use the IIS configuration applet to enable localhost (127.0.0.1) to relay messages through the local SMTP service.

21. What are VSDISCO files?


VSDISCO files are DISCO files that support dynamic discovery of Web services. If you place the following VSDISCO file in a directory on your Web server, for example, it returns references to all ASMX and DISCO files in the host directory and any subdirectories not noted in elements:

xmlns="urn:schemas-dynamicdiscovery:disco.2000-03-17">







21.How does dynamic discovery work?


ASP.NET maps the file name extension VSDISCO to an HTTP handler that scans the host directory and subdirectories for ASMX and DISCO files and returns a dynamically generated DISCO document. A client who requests a VSDISCO file gets back what appears to be a static DISCO document.
Note that VSDISCO files are disabled in the release version of ASP.NET. You can reenable them by uncommenting the line in the section of Machine.config that maps *.vsdisco to System.Web.Services.Discovery.DiscoveryRequestHandler and granting the ASPNET user account permission to read the IIS metabase. However, Microsoft is actively discouraging the use of VSDISCO files because they could represent a threat to Web server security.

What is the CLR?


CLR = Common Language Runtime. The CLR is a set of standard resources that (in theory) any .NET program can take advantage of, regardless of programming language. Robert Schmidt (Microsoft) lists the following CLR resources in his MSDN PDC# article:
Object-oriented programming model (inheritance, polymorphism, exception handling, garbage collection)
Security model
Type system
All .NET base classes
Many .NET framework classes
Development, debugging, and profiling tools
Execution and code management
IL-to-native translators and optimizers
What this means is that in the .NET world, different programming languages will be more equal in capability than they have ever been before, although clearly not all languages will support all CLR services.


23. What does AspCompat="true" mean and when should I use it?


AspCompat is an aid in migrating ASP pages to ASPX pages. It defaults to false but should be set to true in any ASPX file that creates apartment-threaded COM objects--that is, COM objects registered ThreadingModel=Apartment. That includes all COM objects written with Visual Basic 6.0. AspCompat should also be set to true (regardless of threading model) if the page creates COM objects that access intrinsic ASP objects such as Request and Response. The following directive sets AspCompat to true:

<%@ Page AspCompat="true" %>

Setting AspCompat to true does two things. First, it makes intrinsic ASP objects available to the COM components by placing unmanaged wrappers around the equivalent ASP.NET objects. Second, it improves the performance of calls that the page places to apartment- threaded COM objects by ensuring that the page (actually, the thread that processes the request for the page) and the COM objects it creates share an apartment. AspCompat="true" forces ASP.NET request threads into single-threaded apartments (STAs). If those threads create COM objects marked ThreadingModel=Apartment, then the objects are created in the same STAs as the threads that created them. Without AspCompat="true," request threads run in a multithreaded apartment (MTA) and each call to an STA-based COM object incurs a performance hit when it's marshaled across apartment boundaries.

Do not set AspCompat to true if your page uses no COM objects or if it uses COM objects that don't access ASP intrinsic objects and that are registered ThreadingModel=Free or ThreadingModel=Both.

24. Explain the differences between Server-side and Client-side code?


Server side scripting means that all the script will be executed by the server and interpreted as needed. ASP doesn't have some of the functionality like sockets, uploading, etc. For these you have to make a custom components usually in VB or VC++. Client side scripting means that the script will be executed immediately in the browser such as form field validation, clock, email validation, etc. Client side scripting is usually done in VBScript or JavaScript. Download time, browser compatibility, and visible code - since JavaScript and VBScript code is included in the HTML page, then anyone can see the code by viewing the page source. Also a possible security hazards for the client computer.

25. What type of code (server or client) is found in a Code-Behind class?


C#

by Nirav Mehta