Hi,
In my asp.net application i have developed some functionality which was working fine until I added try catch block. The issue is when Response.Redirect("URL"); is getting executed there occurs System.Threading.ThreadAbortException with message "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack".
The reason for this exception is because Response.Redirect, when called with just the URL, or with the URL and a Boolean value of true, calls the Response.End method. Response.End then calls Thread.Abort on the current thread which will result in ThreadAbortException.
So the best solution is to call redirect like Response.Redirect("URL",false) or after try catch block...
Regards
Fauzi
Blog from a software professional, Passionate to work in latest cutting edge technologies in order to get better results in business.
Friday, July 25, 2008
Monday, July 7, 2008
Virus attack which disabled Regedit and Task Manager
Hey all:
Today I felt mysterious to see that the task manager in my machine was disabled & When i tried to run Regedit, an alert was shown saying the user does not have administrative privilege to run this program. Then i ran Anti virus scanning through AVG to get rid of the viruses & found the following steps to enable Task Manger & Regedit from Yahoo Answers...
Hope this should be helpful for people who went puzzled like me :)
Best Regards
Fauzi
Today I felt mysterious to see that the task manager in my machine was disabled & When i tried to run Regedit, an alert was shown saying the user does not have administrative privilege to run this program. Then i ran Anti virus scanning through AVG to get rid of the viruses & found the following steps to enable Task Manger & Regedit from Yahoo Answers...
All these options can be restored through the Group Policy management console.
In order to enable them, please follow the steps below:
1. Open C:\Windows\system32\gpedit.msc
2. In the Group Policy window go to the path:
Local Computer Policy >> User Configuration >> Administrative Templates
3. Find the following entries and perform the necessary adjustments:
- To enable Folder Options:
- Go to Windows Components >> Windows Explorer
- Double-click Removes the Folder Options menu item from the Tools menu
- Select Disabled and confirm with OK
- To enable Task Manager:
- Go to System >> Ctrl+Alt+Del Options
- Double-click Remove Task Manager
- Select Disabled and confirm with OK
- To enable Command Prompt and Regedit:
- Go to System
- Double-click Prevent access to the command prompt
- Select Disabled and confirm with OK
- Double-click Prevent access to registry editing tools
- Select Disabled and confirm with OK
4. Close Group Policy
In order to enable them, please follow the steps below:
1. Open C:\Windows\system32\gpedit.msc
2. In the Group Policy window go to the path:
Local Computer Policy >> User Configuration >> Administrative Templates
3. Find the following entries and perform the necessary adjustments:
- To enable Folder Options:
- Go to Windows Components >> Windows Explorer
- Double-click Removes the Folder Options menu item from the Tools menu
- Select Disabled and confirm with OK
- To enable Task Manager:
- Go to System >> Ctrl+Alt+Del Options
- Double-click Remove Task Manager
- Select Disabled and confirm with OK
- To enable Command Prompt and Regedit:
- Go to System
- Double-click Prevent access to the command prompt
- Select Disabled and confirm with OK
- Double-click Prevent access to registry editing tools
- Select Disabled and confirm with OK
4. Close Group Policy
Hope this should be helpful for people who went puzzled like me :)
Best Regards
Fauzi
Friday, May 9, 2008
Page Life Cycle 2.0 vs 1.1
Hi,
In general we know the page life cycle as follows...
Page request :
The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.
Start :
In the start step, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. Additionally, during the start step, the page's UICulture property is set.
Page initialization :
During page initialization, controls on the page are available and each control's UniqueID property is set. Any themes are also applied to the page. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.
Load :
During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.
Validation :
During validation, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page.
Postback event handling :
If the request is a postback, any event handlers are called.
Rendering :
Before rendering, view state is saved for the page and all controls. During the rendering phase, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream of the page's Response property.
Unload :
Unload is called after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and any cleanup is performed.
And in detail the difference in Page life cycle between ASP.NET 2.0 & 1.1 is shown in the following picture.
Click Here
Regards
Fauzi
In general we know the page life cycle as follows...
Page request :
The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.
Start :
In the start step, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. Additionally, during the start step, the page's UICulture property is set.
Page initialization :
During page initialization, controls on the page are available and each control's UniqueID property is set. Any themes are also applied to the page. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.
Load :
During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.
Validation :
During validation, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page.
Postback event handling :
If the request is a postback, any event handlers are called.
Rendering :
Before rendering, view state is saved for the page and all controls. During the rendering phase, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream of the page's Response property.
Unload :
Unload is called after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and any cleanup is performed.
And in detail the difference in Page life cycle between ASP.NET 2.0 & 1.1 is shown in the following picture.
Click Here
Regards
Fauzi
Thursday, April 10, 2008
WSS 3.0 and MOSS 2007
Hi All,
As every one knows WSS & MOSS both are powerful tools provided by Microsoft. I was surfing on net to compare the key features available in WSS 3.0 vs MOSS 2007. Here is the link i came across & its really too good.
Click here
Here here the comparisons are made based on classifications like
Collaboration
Enterprise Search
Business Process Forms
Management
Enterprise Portal
Enterprise Content Management
Business Intelligence
Platform
Hope this should be helpful...
Regards
Fauzi
As every one knows WSS & MOSS both are powerful tools provided by Microsoft. I was surfing on net to compare the key features available in WSS 3.0 vs MOSS 2007. Here is the link i came across & its really too good.
Click here
Here here the comparisons are made based on classifications like
Collaboration
Enterprise Search
Business Process Forms
Management
Enterprise Portal
Enterprise Content Management
Business Intelligence
Platform
Hope this should be helpful...
Regards
Fauzi
Sunday, April 6, 2008
Tips on Capacity planning for MOSS 2007 Server
Hi
I was looking for links to find maximum number of items allowed in a List and found the following link. It has lot of information's which could be helpful for capacity & Architecture planning while setting up MOSS server.
Link to the information
Regards
Fauzi
I was looking for links to find maximum number of items allowed in a List and found the following link. It has lot of information's which could be helpful for capacity & Architecture planning while setting up MOSS server.
Link to the information
Regards
Fauzi
Tuesday, April 1, 2008
To Find and Replace a String in All Pages inside Document Library in MOSS site
Hey All,
There was an interesting issue that came across in one of moss site when it went live... actually when we edit a content of a page which has content editor webpart through rich text editor, it automatically replaces the relative URL with the fully specified URL. So when the site was moved from development to production, the URLs were still pointing to the development. So to over come this issue the following aspx file with a c# code behind was written to find for a string & replace with a specfied string in All the available pages inside the document library.
Following is its code:
**********************
In-line ASPX file
System.Text
System.Data
System.Configuration
System.Collections
System.Web
System.Web.Security
System.Web.UI
System.Web.UI.WebControls
System.Web.UI.WebControls.WebParts
System.Web.UI.HtmlControls
System.Xml
Microsoft.SharePoint
Microsoft.SharePoint.Administration
Microsoft.SharePoint.Publishing
Microsoft.SharePoint.WebPartPages
System.Runtime.InteropServices
System.IO
script runat server (inside tags)
public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_LOGON_SERVICE = 3;
public const int LOGON32_PROVIDER_DEFAULT = 0;
[DllImport("advapi32.dll", CharSet=CharSet.Auto)]
public static extern bool LogonUser(
String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken
);
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static bool CloseHandle(IntPtr handle);
protected void Button1_Click(object sender, EventArgs e)
{
string user = "YOUR A/C";
string userDomain = "Your Domain";
string password = "A/C Password";
bool impersonate = true;
IntPtr userHandle = new IntPtr(0);
System.Security.Principal.WindowsImpersonationContext impersonatedUser = null;
if (impersonate)
{
bool returnValue = LogonUser(
user,
userDomain,
password,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
ref userHandle
);
if (!returnValue)
{
throw new Exception("Invalid Username");
}
System.Security.Principal.WindowsIdentity newId = new System.Security.Principal.WindowsIdentity(userHandle);
impersonatedUser = newId.Impersonate();
}
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// We get the MOSS site URL from text box URL1.
SPSite mySite = new SPSite(URL1.Text);
SPWeb myWeb = mySite.OpenWeb();
try
{
myWeb.AllowUnsafeUpdates = true;
SPList pagesList = myWeb.Lists["Pages"];
SPListItemCollection myitems = myWeb.Lists["Pages"].Items;
foreach (SPListItem myItem in myitems)
{
SPWebPartCollection webPartCollection = myItem.File.GetWebPartCollection(Storage.Shared);
PublishingPage myPage = PublishingPage.GetPublishingPage(myItem);
foreach (Microsoft.SharePoint.WebPartPages.WebPart x in webPartCollection)
{
if (x.GetType().Name == "ContentEditorWebPart")
{
//Create an XmlElement to hold the value of the Content property.
ContentEditorWebPart ceWebPart = new ContentEditorWebPart();
//Create an XmlElement to hold the value of the Content property.
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlElement = xmlDoc.CreateElement("Content");
xmlElement.InnerText = ((ContentEditorWebPart)x).Content.InnerText.ToString();
if (xmlElement.InnerText.ToString().Contains(TextBox1.Text))
{
// We enter the text to be found in TextBox1 & the text to replace in TextBox2
xmlElement.InnerText = xmlElement.InnerText.ToString().Replace(TextBox1.Text, TextBox2.Text);
// Write the LOG details for investigation later...
StreamWriter stWriter = File.AppendText("D:\\ChangeLog.log");
stWriter.WriteLine(myItem.Url.ToString() + " - " + DateTime.Now);
stWriter.Close();
}
ceWebPart.Content = xmlElement;
((ContentEditorWebPart)x).Content = ceWebPart.Content;
webPartCollection.Web.AllowUnsafeUpdates = true;
webPartCollection.SaveChanges(x.StorageKey);
myPage.Update();
webPartCollection.Web.AllowUnsafeUpdates = false;
}
}
if (myPage.ListItem.ParentList.EnableModeration)
{
myPage.ListItem.File.Approve("");
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
myWeb.Dispose();
mySite.Dispose();
}
});
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
}
if (impersonate)
{
impersonatedUser.Undo();
CloseHandle(userHandle);
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
script ending tag
Form starting tag
URL(TextBox)
From(TextBox)
To (TextBox)
Submit (Button on click calls Button1_Click event )
form ending tag
There was an interesting issue that came across in one of moss site when it went live... actually when we edit a content of a page which has content editor webpart through rich text editor, it automatically replaces the relative URL with the fully specified URL. So when the site was moved from development to production, the URLs were still pointing to the development. So to over come this issue the following aspx file with a c# code behind was written to find for a string & replace with a specfied string in All the available pages inside the document library.
Following is its code:
**********************
In-line ASPX file
System.Text
System.Data
System.Configuration
System.Collections
System.Web
System.Web.Security
System.Web.UI
System.Web.UI.WebControls
System.Web.UI.WebControls.WebParts
System.Web.UI.HtmlControls
System.Xml
Microsoft.SharePoint
Microsoft.SharePoint.Administration
Microsoft.SharePoint.Publishing
Microsoft.SharePoint.WebPartPages
System.Runtime.InteropServices
System.IO
script runat server (inside tags)
public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_LOGON_SERVICE = 3;
public const int LOGON32_PROVIDER_DEFAULT = 0;
[DllImport("advapi32.dll", CharSet=CharSet.Auto)]
public static extern bool LogonUser(
String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken
);
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static bool CloseHandle(IntPtr handle);
protected void Button1_Click(object sender, EventArgs e)
{
string user = "YOUR A/C";
string userDomain = "Your Domain";
string password = "A/C Password";
bool impersonate = true;
IntPtr userHandle = new IntPtr(0);
System.Security.Principal.WindowsImpersonationContext impersonatedUser = null;
if (impersonate)
{
bool returnValue = LogonUser(
user,
userDomain,
password,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
ref userHandle
);
if (!returnValue)
{
throw new Exception("Invalid Username");
}
System.Security.Principal.WindowsIdentity newId = new System.Security.Principal.WindowsIdentity(userHandle);
impersonatedUser = newId.Impersonate();
}
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// We get the MOSS site URL from text box URL1.
SPSite mySite = new SPSite(URL1.Text);
SPWeb myWeb = mySite.OpenWeb();
try
{
myWeb.AllowUnsafeUpdates = true;
SPList pagesList = myWeb.Lists["Pages"];
SPListItemCollection myitems = myWeb.Lists["Pages"].Items;
foreach (SPListItem myItem in myitems)
{
SPWebPartCollection webPartCollection = myItem.File.GetWebPartCollection(Storage.Shared);
PublishingPage myPage = PublishingPage.GetPublishingPage(myItem);
foreach (Microsoft.SharePoint.WebPartPages.WebPart x in webPartCollection)
{
if (x.GetType().Name == "ContentEditorWebPart")
{
//Create an XmlElement to hold the value of the Content property.
ContentEditorWebPart ceWebPart = new ContentEditorWebPart();
//Create an XmlElement to hold the value of the Content property.
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlElement = xmlDoc.CreateElement("Content");
xmlElement.InnerText = ((ContentEditorWebPart)x).Content.InnerText.ToString();
if (xmlElement.InnerText.ToString().Contains(TextBox1.Text))
{
// We enter the text to be found in TextBox1 & the text to replace in TextBox2
xmlElement.InnerText = xmlElement.InnerText.ToString().Replace(TextBox1.Text, TextBox2.Text);
// Write the LOG details for investigation later...
StreamWriter stWriter = File.AppendText("D:\\ChangeLog.log");
stWriter.WriteLine(myItem.Url.ToString() + " - " + DateTime.Now);
stWriter.Close();
}
ceWebPart.Content = xmlElement;
((ContentEditorWebPart)x).Content = ceWebPart.Content;
webPartCollection.Web.AllowUnsafeUpdates = true;
webPartCollection.SaveChanges(x.StorageKey);
myPage.Update();
webPartCollection.Web.AllowUnsafeUpdates = false;
}
}
if (myPage.ListItem.ParentList.EnableModeration)
{
myPage.ListItem.File.Approve("");
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
myWeb.Dispose();
mySite.Dispose();
}
});
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
}
if (impersonate)
{
impersonatedUser.Undo();
CloseHandle(userHandle);
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
script ending tag
Form starting tag
URL(TextBox)
From(TextBox)
To (TextBox)
Submit (Button on click calls Button1_Click event )
form ending tag
Monday, March 31, 2008
Your own custom error page for MOSS 2007 site
Hey All,
I had a requirment to show custom error page in my MOSS 2007 site. I tried couple of options like changing the node customErrors "On" & specified URL for DefaultRedirect in Web.config And editing the custom error locations in the properties of the site.
Both of them did not work & i tried the steps mentioned in the following URL.
Click Here
It worked fine :)
I had a requirment to show custom error page in my MOSS 2007 site. I tried couple of options like changing the node customErrors "On" & specified URL for DefaultRedirect in Web.config And editing the custom error locations in the properties of the site.
Both of them did not work & i tried the steps mentioned in the following URL.
Click Here
It worked fine :)
Subscribe to:
Posts (Atom)