Friday 29 July 2011

What is the sequence of events that happens when a client requests a .net apsx page?

User requests an application resource from the Web server:
The life cycle of an ASP.NET application starts with a request sent by a browser to the Web server (for ASP.NET applications, typically IIS). ASP.NET is an ISAPI extension under the Web server. When a Web server receives a request, it examines the file-name extension of the requested file, determines which ISAPI extension should handle the request, and then passes the request to the appropriate ISAPI extension. ASP.NET handles file name extensions that have been mapped to it, such as .aspx, .ascx, .ashx, and .asmx.


Note
If a file name extension has not been mapped to ASP.NET, ASP.NET will not receive the request. This is important to understand for applications that use ASP.NET authentication. For example, because .htm files are typically not mapped to ASP.NET, ASP.NET will not perform authentication or authorization checks on requests for .htm files. Therefore, even if a file contains only static content, if you want ASP.NET to check authentication, create the file using a file name extension mapped to ASP.NET, such as .aspx.



Note
If you create a custom handler to service a particular file name extension, you must map the extension to ASP.NET in IIS and also register the handler in your application's Web.config file


ASP.NET receives the first request for the application:

When ASP.NET receives the first request for any resource in an application, a class named ApplicationManager creates an application domain. Application domains provide isolation between applications for global variables and allow each application to be unloaded separately. Within an application domain, an instance of the class named HostingEnvironment is created, which provides access to information about the application such as the name of the folder where the application is stored.
The following diagram illustrates this relationship:
Application Topgraphy Overview Graphic
ASP.NET also compiles the top-level items in the application if required, including application code in the App_Code folder.



ASP.NET core objects are created for each request:
After the application domain has been created and the HostingEnvironment object instantiated, ASP.NET creates and initializes core objects such as HttpContext, HttpRequest, and HttpResponse. The HttpContext class contains objects that are specific to the current application request, such as the HttpRequest and HttpResponse objects. The HttpRequest object contains information about the current request, including cookies and browser information. The HttpResponse object contains the response that is sent to the client, including all rendered output and cookies.

An HttpApplicationobject is assigned to the request:
After all core application objects have been initialized, the application is started by creating an instance of the HttpApplication class. If the application has a Global.asax file, ASP.NET instead creates an instance of the Global.asax class that is derived from the HttpApplication class and uses the derived class to represent the application.


Note
The first time an ASP.NET page or process is requested in an application, a new instance of HttpApplication is created. However, to maximize performance, HttpApplication instances might be reused for multiple requests.


When an instance of HttpApplication is created, any configured modules are also created. For instance, if the application is configured to do so, ASP.NET creates a SessionStateModule module. After all configured modules are created, the HttpApplication class's Init method is called.


The following diagram illustrates this relationship:
Application Environment Graphic


The request is processed by theHttpApplicationpipeline:

The following events are executed by the HttpApplication class while the request is processed. The events are of particular interest to developers who want to extend the HttpApplication class.
  1. Validate the request, which examines the information sent by the browser and determines whether it contains potentially malicious markup. For more information, see ValidateRequest andScript Exploits Overview.
  2. Perform URL mapping, if any URLs have been configured in the UrlMappingsSection section of the Web.config file.
  3. Raise the BeginRequest event.
  4. Raise the AuthenticateRequest event.
  5. Raise the PostAuthenticateRequest event.
  6. Raise the AuthorizeRequest event.
  7. Raise the PostAuthorizeRequest event.
  8. Raise the ResolveRequestCache event.
  9. Raise the PostResolveRequestCache event.
  10. Based on the file name extension of the requested resource (mapped in the application's configuration file), select a class that implements IHttpHandler to process the request. If the request is for an object (page) derived from the Page class and the page needs to be compiled, ASP.NET compiles the page before creating an instance of it.
  11. Raise the PostMapRequestHandler event.
  12. Raise the AcquireRequestState event.
  13. Raise the PostAcquireRequestState event.
  14. Raise the PreRequestHandlerExecute event.
  15. Call the ProcessRequest method (or the asynchronous version IHttpAsyncHandler.BeginProcessRequest) of the appropriate IHttpHandler class for the request. For example, if the request is for a page, the current page instance handles the request.
  16. Raise the PostRequestHandlerExecute event.
  17. Raise the ReleaseRequestState event.
  18. Raise the PostReleaseRequestState event.
  19. Perform response filtering if the Filter property is defined.
  20. Raise the UpdateRequestCache event.
  21. Raise the PostUpdateRequestCache event.
  22. Raise the EndRequest event.
  23. Raise the PreSendRequestHeaders event.
  24. Raise the PreSendRequestContent event.

What is the key word you use in sql server stored procs to prevent locking?

WITH (NO LOCK)

What assembly do you reference for transaction processing on the .Net framework?

System.Transactions

Broken Function: There are some problems with the code below. Identify at least 4 issues.

private void GetCustomers()
{

System.Text.StringBuilder sBuilder = new System.Text.StringBuilder("");
System.Data.SqlClient.SqlDataReader oDR;
String sOutput;
System.Data.SqlClient.SqlConnection oConn;

try
{
System.Data.SqlClient.SqlCommand oCmd = new System.Data.SqlClient.SqlCommand("usp_GetCustomerNames",oConn);
                   
oCmd.CommandType = CommandType.StoredProcedure;
oDR = oCmd.ExecuteReader(CommandBehavior.CloseConnection);

while (oDR.Read)
{
sBuilder.Append(oDR("ForeName") & ";");
}
               
}
catch (Exception ex)
{

}

oDR.Close();

return sOutput;
}




ANS:


1) System.Data.SqlClient.SqlConnection oConn;
The connection object declared but then is not instantiated with a valid connection string,
for eample oConn.ConnectionString = “Data Source=(local);Database=AdventureWorks;Integrated Security=SSPI”


2)System.Text.StringBuilder("");
StringBuilder constructor arguments cannot be empty string

3) return sOutput;
No valid string is assigned to the sOutput variable returned by the GetCustomers() function.

4)
catch (Exception ex)
{

}
There is no code written to deal with the exception in the try/catch exception handler.
for example, to display a message to the user, or cancel the exception in order to allow processing to continue uninterruppted.

In CSS what would be the effects of and differences between the following:




1    #dvHeader UL LI A { color:red }
2    .dvHeader UL LI A { color:red }
3    #dvHeader A { color:red }
4    #dvHeader > A { color:red }


# is used as an id selector hence,
#dvHeader would match an Anchor elements in an un-numbered list's list Item, and of class dvHeader (className of dvHeader) [and set the InnerHTML (text ) contained within any one of these tags to the color red].

. is used for a style class definition hence,
.dvHeader would by used to assign the specified attributes (in this case the color red) to the Anchor element of a List Item of an un-numbered list
of class .dvHeader.

#dvHeader > A {color:red} would be used to match an anchor with the id value of #dvHeader and set its highlight color to red

What Javascript would assign the function “fncDoSomething” to the click event of a DIV with Id=”dvMyDiv”?

<DIV Id=dyMyDiv onClick= “fncDoSomething()”></DIV>

What Javascript could be used to display an alert style message of “Close Form, Are you sure?”, and then depending on the answer, close the current window?

var r=confirm("Close Form, Are You Sure?")
  if (r==true)
    {
//close the form  
CurrentWindow.Close
    }
  else
    {
    //do nothing
return

    }

In CSS, what won’t inherit its styles from the BODY tag?

The <HTML> tag

How would you provide Column Click sorting for a date column on a List View or Data Grid?

Date column sorting on a click command may be implemented with a bubble sort

What is the difference between dropping out of scope and setting to nothing?

Dropping out of scope means that an object (or variable) no longer has visiblity (and is no longer valid) in the current procedure currently being executed, whereas setting an object reference to Nothing actually removes the object from memory (destroys it) altogether.

how can you assess the likely performance of some TSQL without actually executing it

set showplan_all on

"The page is trying to close the window" warning message.

Fix: Javascript: How to Close Browser Window (window.close()) Without Warning
There is function window.close() in javascript to close browser window. If we call it from the main browser window (not the one opened with window.open()) - we get: "The page is trying to close the window" warning message.
This warning message shows up every time one tries to close browser window with window.close() function. It seems impossible to close the most outer main browser window and not to get this message.
But wait... window.close() function implementation is just so simple. It checks window.opener. If "opener" equals empty string it suspects that we talk about parent window (not the one that was opened with window.open(...)) and pop-ups warning. And it is easy to work around:
< a href="javascript:window.opener='x';window.close();">Close< /a>

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Fix: Remove AutopostBack=true from the dropdown control in the aspx page

CalendarExtender loses style when placed inside a web user control.

Fix1: http://forums.asp.net/p/1068114/1550697.aspx
As a workaround, try this - in the page that loads the usercontrol:
1) add another textbox to the page, outside the updatepanel
2) add a calendar extender and point at the textbox
3) on the textbox set 'style="display:none;" so it doesnt' show up on the page.
This should get the styles loaded early enough so this doesn't happen while we figure out a fix.
Fix2: Don't know how much this helps but I noticed that if you set EnablePartialRendering ="false" the script manager the original css is retained.

Could not find a part of the path 'C:\Inetpub\wwroot\website_url\project_folder\foldername\'

Fix: Check to make sure web.config file has appsettings entry pointing to the correct path

CuteFTP 8.0 pro, Socket Error 10054

Fix: Check to make sure FTP Service is Started on the VPS Server. Then , for additional info see: http://kb.globalscape.com/KnowledgebaseArticle10235.aspx

The breakpoint will not currently be hit. No symbols have been loaded for this document.

In the Visual Studio IDE, when I set a breakpoint at a line of code, and start debugging, the breakpoint becomes that hollow maroon circle with a warning that says
'The breakpoint will not currently be hit. No symbols have been loaded for this document.'

I've read a bunch of articles about making sure you're running in debug versus release mode, and making sure you deleted your obj AND bin folders. Doesn't always work for me.

While debugging in Visual Studio, click on Debug > Windows > Modules. The IDE will dock a Modules window, showing all the modules that have been loaded for your project.
Look for your project's DLL, and check the Symbol Status for it.
If it says Symbols Loaded, then you're golden. If it says something like Cannot find or open the PDB file, right-click on your module, select Load Symbols, and browse to the path of your PDB.

I've found that it's sometimes necessary to :
stop the debugger
close the IDE
close the hosting application
nuke the obj and bin folders
restart the IDE
rebuild the project
go through the Modules window again

Once you browse to the location of your PDB file, the Symbol Status should change to Symbols Loaded, and you should now be able to set and catch a breakpoint at your line in code.

Also Check the Bin folder of the project and make sure that the dll file is not EXCLUDED from the project. right-click to INCLUDE if excluded.

Most of all: Also click on Build menu, select  Configuration Manager...set Active Solution Configuration to "Debug"

System.UnauthorizedAccessException Access to the path 'c:\inetpub\wwwroot\websitefolder\images\image.jpg' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at System.Web.UI.WebControls.FileUpload.SaveAs(String filename) at website.uploadClass.HasFile(Object sender, EventArgs e)

FIX: is to set Write permissions to TRUE on the Security tab (within folder properties) for the IIS_WPG (DOMAIN_NAME\IIS_WPG) Group
on C:\Inetpub\wwwroot\websitefolder\images\ folder on the VPS.

As default for most folders, the only Groups with Write permissions are:
i)  Administrators (DOMAIN_NAME\Administrators)
ii) OWS_3894452191_admin (DOMAIN_NAME\OWS_3894452191_admin)
iii)SYSTEM

If aspx files have no associated designer.vb files available (but they do all have the .vb code behind files)

Fix: if you create a new website (not a web application) then there will not be any designer file and event wiring is through the aspx.
You've most likely made an ASP .NET Web "Site", rather than an ASP .NET "Web Application Project" (only available in VS 2005 SP1 or VS 2008).

With web "sites", there is no .designer.vb file because the code is
dynamically compiled when it is called. You'll notice that in the Page
Directives (in the .aspx source code) that the AutoEventWireUp directive is
set to true, this means that as long as your event handler names are a
combination of the control name, an underscore and the event name, along
with appropriate parameters, the event will automatically "wire up" to the
event handler.

UNMOUNTABLE_BOOT_VOLUME

Fix:
http://support.microsoft.com/?kbid=297185&sd=RMVP
see also:
http://aumha.org/a/stop.htm
see also:
http://www.google.co.uk/search?hl=en&source=hp&q=STOP+0x000000ED+UNMOUNTABLE_BOOT_VOLUME&btnG=Google+Search&meta=&aq=f&oq=

Exception Details: System.ArgumentOutOfRangeException: 'dropdownlist' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

Fix: Make sure select list only contains all possible values from database. Make sure database can only accept valid values on the select list markup

Crystal Reports Ambiguous DLLs issue when upgrading Crystal Reports from v10 to v12 :

Fix:
delete copy of CrystalDecisions.Web.dll v-10.2.51014.0 module
from C:\Inetpub\wwwroot\websitefolder\bin
then:
copy
CrystalDecisions.Web.dll v-12.0.2000.683
from
C:\Program Files\Business Objects\Common\4.0\managed\dotnet2
to
C:\Inetpub\wwwroot\websitefolder\bin

Microsoft SQL Native Client error '80040e31' Query timeout expired

Fix:Under the main SQL Server connection in SSMSE, select Connections page, set Remote query timeout (in seconds, 0 = no timeout) to 0

It's not possible to install Windows XP on top of (over) a Windows Vista factory installation.

Fix: (Download KillDiskSuite.) Create bootable KillDiskSuite CD and execute a drive wipe.
Installation from windows XP w/Service Pack 2 CD won't run without first installing Win XP Professional.

underlying hidden error is 'procedure or function has too many arguments specified' error. System.Net.WebException: An exception occurred during a WebClient request. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Inetpub\wwwroot\websitename\photos\5600.jpg'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at System.Net.WebClient.DownloadFile(Uri address, String fileName) --- End of inner exception stack trace --- at System.Net.WebClient.DownloadFile(Uri address, String fileName) at System.Net.WebClient.DownloadFile(String address, String fileName) at ftpClass.FileTransfer.Download() in C:\Inetpub\wwwroot\websitename\App_Code\FileTransfer.vb:line 50

Fix: in UtilHelper.vb.ins_newrow(), add a call to UtilHelper.vb.ClearParameters()
before call to ftpClass.FileTransfer.DownloadPhoto()

Sys.Webforms.PageRequestManagerServerErrorException: An unknown error occured while processing the request on the server. The status code returned from the server was: 500

Fix: Make sure aspx page has a Scripmanager control embedded in the Markup code. For content pages, insert Scripmanager into Master.aspx pages.

The session setup from computer 'computername' failed because the security database does not contain a trust account 'computername$' referenced by the specified computer.

If you get this error when trying to set up a new workstation on an existing network domain...
Fix: If 'computername' is a Domain Controller, then the trust associated with 'computername$' should be deleted.  If 'computername' is not a Domain Controller, it should be disjoined from the domain, and then rejoined to the domain.
Take for example where computername name might be "ATLANTIS", or "GERONIMO", etc.

undeliverable email errors (NDR errors for mail sent from domain on a Hosted VPS)

Fix: Hosting provider needs to set up reverse DNS lookup set up for your IP address, to stop emails sent from it being rejected by other Mail Servers.

CuteFtp error: ERROR:> Can't read from control socket. Socket error = #10054.

Fix: Use IPsec on server to specify allowed ftp client IP address. And set up excptions list in Windows Firewall on Server.

Outlook Mailbox Access error

Fix: Mailbox access issue appears to be resolved by setting an additional non-inherited Exchange Domain Server entry with just 'Full Mailbox Access' under AD/SBS Users Advanced Security Settings.
Note: that there should already be two other Exchange Domain Server entries but which are Inherited from 'Parent Object',
one with 'Deny - Full Mailbox Access',
and a second with 'Allow - Special' (allows all except 'Associated External account')

Exception message: Server was unable to process request. ---> Computer name could not be obtained.

Fix: recompile and republish the Webservice being called

Exception message: Procedure or function sp_procedurename has too many arguments specified.

If this error results from attempting to call a database stored procedure via ado.net from within an asp.net aspx page,

Fix: modify aspx page to rename procedure arguments to match the stored procedure arguments

#50070: Unable to connect to the database STS_servername_1 on Servername\SharePoint. Check the database connection information and make sure that the database server is running.

Fix: open Sharepoint Central Administration and open Configure Virtual Server for Central Administration, select Use an Existing Application Pool, and select MSSahrePointAppPool

Wednesday 27 July 2011

A potentially dangerous Request.Form value was detected from the client ...

One work around is to set validateRequest="false" in Page element in web.config. Only trouble with that is, it allegedly then leaves the page vulnerable to script-injection attacks.
And apparently Html.Encoding() the control’s contents on the grid alone will not prevent the error either, but using a combination of both steps, is a fairly acceptable workaround.

Alternatively, validateRequest="false" can be used just in the page directive of a specific page rather than in the web.config file, and the second step is to then html encode the contents of controls on the web page or grid view. e.g. Textbox.Text = HttpUtility.HtmlEncode(databasevalue)

Tuesday 26 July 2011

An error occurred on the server when processing the URL. Please contact the system administrator


Fix: IIS Settings:
            cscript 
%systemdrive%\inetpub\adminiscripts\adsutil.vbs set w3svc/AspScriptErrorSentToBrowser true      (to allow error message send to client)
by default, IIS 7 (ASP) does not send errors to the browser.  Enable the setting and see what error is displayed.  Also, make sure classic asp is installed.

first blog

Finally adapting bits of my trusty offline error-log archive into this online blog, which documents various IT tech problems and solutions that can be used to overcome them; aggregating my own solutions to various problems, as well as suggested solutions from other techies,  into one easily accessible place. Hopefully over time others may find some helpful tips here as well. Happy hunting!