To Change your web config in ASP.Net you can try this code:
var configuration = WebConfigurationManager.OpenWebConfiguration("~");
var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings");
section.ConnectionStrings["mySTRING"].ConnectionString = “Data Source=192.168.1.1;Initial Catalog=MYDATABASENAME;User ID=USER;Password=PASSS”;
configuration.Save();
April 16, 2013
Change a web.config programmatically with Aps.Net C#
February 19, 2013
HttpHandlers IIS6 vs IIS7.5, registering
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
You are trying to place your httphandlers in your web config from your working environment to your server and you start receiving 500 - Internal server error. One of the reasons is that on your development environment you have IIS6 handlers and you are trying to copy paste to your IIS7 or IIS7.5 web.config. But things are changed numbers are changed and sections where you should define your handlers are changed so:
The thing that in iis6 was: <system.web> now is <system.webServer>in IIS7.5 so your web.config should look like this:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<!-- modules go here -->
</modules>
<handlers>
<!-- HERE is going your HANDLER-->
</handlers>
Interesting is that you can’t just copy and paste your IIS6 handler to IIS7.5 section and to start to working, if you do that than again you will receive server 500 error, you should rearrange a little bit your iis6 HttpHandler and after that put in handlers section. i will put two examples one is IIS6 and another is IIS7. 5 working handler and you will notice differences. I was trying to register oabout upload file with progress bar asp.net control (ASP.NET File Upload Progress - Use of StatusPanel Control), and at the end i finish with this:
IIS6 HttpHandler:
<httpHandlers>
<add verb="*" path="OboutInc.UploadProgressHandler.aspx" type="OboutInc.FileUpload.UploadProgressHandler, obout_FileUpload, Version=1.10.806.1, Culture=neutral, PublicKeyToken=c8b4009f4d53d5e5" />
</httpHandlers>
IIS7.5 HTTP Handler:
<handlers>
<add name="OboutUploadModule" path="OboutInc.UploadProgressHandler.aspx" verb="*" type="OboutInc.FileUpload.UploadProgressHandler, obout_FileUpload, Version=1.10.806.1, Culture=neutral, PublicKeyToken=c8b4009f4d53d5e5" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
This worked for me, and control was working like expected.
February 14, 2013
Asp.Net determine if file is an image c# by image file headers
Here you can download simple web site in asp.net C# in which you will find method that determine format of image by checking headers of file, according to this info tutorial
You can download project here or imgchk_by_heder_c#.zip
February 13, 2013
Project has no project.properties file! Edit the project properties to set one.
If you receive this kind of error in your android app, than don’t import your android app but click :
File -New -Project.. and select Android Project from existing code, and select your root project directory.
funny characters when importing project that contain Cyrillic in Eclipse
If you have funny characters when you import project in Eclipse that contains Cyrillic or Utf-8 characters than force your eclipse to import projects in utf -8 encoding by going to:
Window - Preferences - General - Workspace - Text file encoding choose Other and select UTF-8
and, for more fine-grained tuning by content type:
Window - Preferences - General - Content types
February 8, 2013
My Update panel won’t work ASP.Net
On your page you have, Your scriptmanager on top, you have, your panel and your control, you have defined timer, but your update panel won’t work. So what can be wrong?
If you check Javascript console from your browser you can see something like this:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:25624/my_project/ScriptResource.axd?d=U8iTLB_pxZ1-Tf…8S55vlYuUcr63nt5ieZRabiXzGuZZIMv4sx13ImjRAH_qcIgV91n0&t=634882578938732455
all you need to do is to check your web.config and to see if your httphandlers are defined in your system.web section like this:
<system.web>
<httpHandlers>
<remove verb=”*” path=”*.asmx”/>
<add verb=”*” path=”*.asmx” validate=”false” type=”System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
<add verb=”GET” path=”ScriptResource.axd” type=”System.Web.Handlers.ScriptResourceHandler” validate=”false”/>
</httpHandlers>
</system.web>
February 7, 2013
Access session variable in Httphandler
When you want to get access to your Session State from an ASHX or HttpHandler, you need to implement IReadOnlySessionState:
using System;
using System.Web;
using System.Web.SessionState;
public class DownloadHandler : IHttpHandler, IReadOnlySessionState
{
public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext ctx)
{
ctx.Response.Write(ctx.Session["fred"]);
}
}
February 6, 2013
Unable to cast object of type ‘System.Web.UI.HtmlControls.HtmlAnchor’ to type ‘System.Web.UI.HtmlControls.HtmlGenericControl’.
If you are searching control in your master page, and you recieve this error than you may try this way to find and add atributes to your control:
((System.Web.UI.HtmlControls.HtmlAnchor)Page.Master.FindControl("itm_1")).Attributes["class"] = “your_css_class”;
January 28, 2013
How do I make an html redirect page
in the code change url with your URL:
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<html>
<head>
<title>Your Page Title</title>
<meta http-equiv=”REFRESH” content=”0;url=http://www.YOURADDRE”></HEAD>
<BODY>
Optional page text here.
</BODY>
</HTML>
Get application path in c#
easiest way to get path of your Application:
string exePath =System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetEntryAssembly().Location);
November 20, 2012
Magento switch stores with Session ID
If you like to switch sotres in your magentowebsite, it’s quite likely that you’d want to maintain the shopping cart status across those domains, especially if they’re all related and the customer’s logins work on every site. The best way of doing this is to attach the customer’s session ID to any links you make to the other websites. As with many customer attributes, this can be done with a simple line of code:
< ?php echo Mage::getModel("core/session")->getEncryptedSessionId(); ?>
If you want your links to send across your session ID, simply attach it to the href as a query:
<a href="http://www.domain2.com/?SID=<?php echo Mage::getModel("core/session")->getEncryptedSessionId(); ?>&___store=YourStore">Bla</a>
try Catch & Response.Redirect
If you have try catch block, and in your catch block you have Response.redirect(URL), you will experiences that your code always redirects, although there is no error in your try block.
Reason is because when you use response.redirect, that throws a ThreadAbortException, so you can use this code to avoid this error:
try
{
// Do some cool stuff that might break
}
catch(ThreadAbortException)
{
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch(Exception e)
{
// Catch other exceptions
Response.Redirect("~/myErrorPage.aspx");
}
November 13, 2012
Invalid postback or callback argument.
Invalid postback or callback argument. Event validation is enabled using in configuration or < %@ Page EnableEventValidation=”true” %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
If you receive this error simple resolution is adding this into the section of your web.config file:
<pages enableEventValidation="false" />
November 6, 2012
November 5, 2012
Change target framework Visual Studio
From the main menu choose Website->Start opitons -> Build and in the left pane select Target framework