| |
|
posted by Tihomir Ivanov on 18 February 2010 06:29
When you install updates or a new software on your pc, you install soem version of Microsoft .NET Framework. It contains a common runtime application that may be required by applications you’re running. During the installation, an account, which is named ASP.NET is created. If your pc previously displayed your desktop immediately after starting, you may notice a ‘Welcome’ screen when you run the computer with your existing user account and an ASP.NET account. It happens because after the installation, there are 2 accounts on your computer.
The account does not allow remote or interactive login and only has "guest" level permissions. It cannot be used by another individual or by Microsoft to log in to your machine.
If you’re just using your computer for personal use (i.e. if you’re not a developer who needs develop software with IIS) you can safely remove this account in one of the following ways:
1) Uninstall the .NET Framework (note: this will cause applications using .NET Framework to stop working):
• Open the Control Panel
• Open Add/Remove Programs
• Select Microsoft .NET Framework 1.1
• Click Change/Remove
2) Delete the account, leaving the Microsoft .NET Framework installed:
• Launch the Computer Management tool within your Administrative Tools folder (under Control Panel)
• Select the Local Users and Groups node
• Click the Users sub node, highlighting the ASPNET account
• Right click the highlighted account and choose delete
Either of way 1 and way 2 will completely remove the ASP.NET account from your system.
Learn More
http://support.microsoft.com/default.aspx?scid=kb;en-us;827072
|
|
posted by Tihomir Ivanov on 16 January 2010 19:17
You may often use the Response's Redirect method to open new pages, ex:
Response.Redirect("http://www.devtheweb.net");
It will open the url in the same window.
If you want to open url by server side in a new window, it cannot be done using the Response's Redirect method.
But it can be done using JavaScript, here is an example:
ClientScript.RegisterStartupScript(typeof(Page), "key", "<script>window.open('http://www.devtheweb.net','_blank')</script>");
|
|
posted by Tihomir Ivanov on 02 January 2010 13:37
Sometimes you may have strings to represent dates (ex. 20100102 that represents 2010 January 2), here's an example how it can be converted to DateTime:
string dtString = "20100102";
IFormatProvider culture = new CultureInfo("en-EN", false);
DateTime dt = DateTime.ParseExact(dtString, "yyyyMMdd", culture, DateTimeStyles.NoCurrentDateDefault);
Now, if you want to convert DateTime variable to string in the format above, here's an example how it can be done:
String dtNewString = String.Format("{0:dd/MM/yyyy}", dt);
|
|
posted by Tihomir Ivanov on 08 December 2009 16:57
I'm writing ability user of my site http://www.devtheweb.net to have ability to change their avatar photos by uploading their own image files.
In this article you can find:
- how to check on server-side if file is selected by FileUpload
- how to check on server-side if Image file is selected by FileUpload
- how to check Image dimensions from file selected by FileUpload
In .aspx file we have a FileUpload Control, Button to submit file and a Label to output result in it:
<div>
<asp:FileUpload ID="_customImageFU" runat="server" />
</div>
<div>
<asp:Label ID="_resultLbl" runat="server" ForeColor="Red"></asp:Label>
</div>
<div>
<asp:Button ID="_uploadImageBtn" runat="server" onclick="_uploadImageBtn_Click" Text="Upload" />
</div>
in code-behind file, we handle the Submit Button Click and check for valid image:
protected void _uploadImageBtn_Click(object sender, EventArgs e)
{
string extension, filename;
try
{
//t checks if file exists
if (!_customImageFU.HasFile)
{
_resultLbl.Text = "Please, Select a File!";
return;
}
//t checks file extension
extension = System.IO.Path.GetExtension(_customImageFU.FileName).ToLower();
if (!extension.Equals(".jpg") && !extension.Equals(".jpeg")
&& !extension.Equals(".gif") && !extension.Equals(".png"))
{
_resultLbl.Text = "Only image files (.JPGs, .GIFs and .PNGs) are allowed.";
return;
}
//t checks if image dimensions are valid
if (!ValidateFileDimensions(100, 100))
{
_resultLbl.Text = "Maximum allowed dimensions are: width <= 100px and height <= 100px.";
return;
}
filename = Server.MapPath("~/some_folder/") + "some-file-name" + extension;
_customAvatarFU.SaveAs(filename);
}
catch (Exception)
{
//t handle the exception
}
}
public bool ValidateFileDimensions(int aHeight, int aWidth)
{
using (System.Drawing.Image image = System.Drawing.Image.FromStream(_customImageFU.PostedFile.InputStream))
{
return (image.Height <= aHeight && image.Width <= aWidth);
}
}
That's all :)
|
|
posted by Tihomir Ivanov on 24 November 2009 16:13
Here's a simple example how you can detect URLs in some text and replace them with html code for hyperlinks:
string someText = "here's a simple text that contains urls in it like http://www.aspnetsource.com or http://aspnetsource.com or http://aspnetsource.com";
// we create a Regex object with pattern to detect URLs
Regex reg = new Regex(@"((http|https|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))*[\w\d:#@%/;$()~_?\+-=\\\.&]*)");
string htmText = reg.Replace(someText, "<a href=\"$1\">$1</a>");
/* now htmlText contains formatted html code with hrefs:
here's a simple text that contains urls in it like <a href="http://www.aspnetsource.com">http://www.aspnetsource.com</a> or <a href="http://aspnetsource.com">http://aspnetsource.com</a> or <a href="http://aspnetsource.com">http://aspnetsource.com</a>
*/
|
|
posted by Tihomir Ivanov on 17 November 2009 13:22
It's very easy to display RSS Feeds using XmlDataSource and DataList:
Just copy the code below and replace the DataFile value with the RSS Feed url you want
<asp:XmlDataSource ID="RSSDataSource" Runat="server" DataFile="http://www.dev-the-web.com/blog/feed/"
XPath="rss/channel/item" EnableCaching="true" CacheDuration="300" CacheExpirationPolicy="Sliding" />
<asp:DataList ID="dlRSSItems" Runat="server" DataSourceID="RSSDataSource">
<ItemTemplate>
<li><a href='<%# XPath("link") %>'><%# XPath("title") %></a></li>
</ItemTemplate>
</asp:DataList>
That's all :)
|
|
posted by Tihomir Ivanov on 12 November 2009 16:40
Sometimes it's necessary to get the current Theme Name and it's physical folder path (ex. to check if some file exists in the current theme folder).
We usually define the corrent theme in the WebConfig File:
...
<pages theme="Default" ... >
...
Now, how we could get the current theme name programmatically (C# example):
using System.Web.Configuration;
...
PagesSection pageSection = ConfigurationManager.GetSection("system.web/pages") as PagesSection;
//t pageSection contains property Theme with value - the name of the current Theme
string currentTheme = pageSection.Theme;
//t now we could get the current theme folder physical path
string themeDirPhysicalPath = HttpContext.Current.Server.MapPath("~/App_Themes/" + pageSection.Theme);
...
well, that seems to be All :)
|
|