Friday, October 12, 2012

Create Https Request C#

I was writing a client application to communicate with our  server application built on asp.net.
client application worked perfactly with http port but when i tried to connect it to https port which was using a self signed certificate it raises an error
"The remote certificate is invalid according to the validation procedure" so for my debugging purpose i needed to bypass that certificate checking so i tried like that

provide a RemoteCertificateValidationCallback delegate



private static bool ValidateCertificate(object sender,X509Certificate cert,X509Chain chain,SslPolicyErrors polErrors)
        {
            if (Convert.ToBoolean("true"))
            {
                // allow any old dodgy certificate...
                return true;
            }
            else
            {
                return polErrors == SslPolicyErrors.None;
            }
        }

and attach it to ServerCertificateValidationCallback property of ServicePointManager.just before the line where Getting Response from server


ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateCertificate);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myRequest.GetResponse();

Also included the following namespaces as well

 System.Security.Cryptography.X509Certificates;
 System.Net.Security;



Monday, September 24, 2012

Resolve Disk Issue on AWS RDS MYSQL

I was having a lot of trouble with my RDS instances running MySql 5.1 with respect to the disk usage ,
they were 40 GB instances and were almost full thought deletion of unused records was taking no effect on the RDS console monitoring screen for the disk space 
there were no binary logs , late query logs , general logs ,every thing was appearing to be good but server was restricting operations on tables due to disk space shortage . 
i tried to delete unused data but what i got that the freeable space is increased by the disk space was having same issues i checked into specific tables for their sized by using query 

SELECT table_name "Table Name",
SUM( data_length + index_length ) / 1024 /
1024 "Table Size in MB",
SUM( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES where table_schema='test-socerwar'
GROUP BY table_NAME
order by data_length desc;


here I found the tables which were having large free able memory and after running the command 

Optimize table  TABLENAME

 for those specific tables , every thing turned to be good for me.
hope it will help others who are new to  MySQL like Me.


Sunday, June 24, 2012

Asp.net Authentication and Authorization in Winodws Applications

i was developping  a web application with asp.net authentication model for a client.
every thing went well but certainly client asked for a desktop version with of course authroization and authentication. both applications were hitting to same database so same authentication model was required for desktop application was required
so by just adding the following configurations in app.config of my desktop application it was possible to use Membership of asp.net authentications in windows appliation
<membership>
    
      <providers>
       
        <remove name="AspNetSqlMembershipProvider"/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web,
           Version=2.0.0.0, Culture=neutral,
           PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="MedBillUtility.Properties.Settings.AFileStorageDBConnectionString" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="3" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
      </providers>
     
    </membership>
but then i realized thought authentication is done but i m still unable to authorization because role manger is not available so to enable role manger so i had to add following section in my app.config as well under System.web
   <roleManager enabled="true">
      <providers>
        <remove name="AspNetSqlRoleProvider"/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web,
           Version=2.0.0.0, Culture=neutral,
           PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="MedBillUtility.Properties.Settings.AFileStorageDBConnectionString" applicationName="/"/>
      </providers>
    </roleManager>
and all worked .

Microsoft.Jet.OLEDB.4.0 provider is not registered on the local machine.

I was having this issue on my client machine , with windows server 2008 os application wa working fine on my machine , but when deployed it was producing the issue that provider is not registered .
I tried to chage the provider to 'Microsoft.ACE.OLEDB.12.0'  but the issue remained unresolved.
i then downloaded the 64 bit egine for Access from microsoft and it worked for me
Access database engine can be found here
http://www.microsoft.com/en-us/download/details.aspx?id=13255

Thursday, May 31, 2012

Showing Summery Row in Asp.net Grid View


I was working on an asp.net grid and required to show the total of a column in footer row,while considering tradaitional options of using RowDataBound event and then looping through all the rows of attached datasource and then adding them to any variable and then displaying it in footer row . i just wanted to avoid those extra loops cause i wanted to show total of each column in my grid and .
so i thought of Linq to datasets options and to use sum function like
here
I used <FooterTemplate> inside   <Template Field> for that specific column 
my column name is WO
and code look likes here

<asp:TemplateField HeaderText="WO">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("WO") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("WO") %>'></asp:Label>
                                    </ItemTemplate>
                                    <FooterTemplate>
                                      <asp:Label ID="lblFooterWO" runat="server" Text=""></asp:Label>
                                    </FooterTemplate>
                                </asp:TemplateField>


Do not forget to set ShowFooter property of Grid View to True like 

ShowFooter="true"

Finally in the RowDataBound event of the grid calculate the sum and bind it like

 protected void grdBilling_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            //DataTable dt = ((System.Data.DataRowView)(e.Row.DataItem)).Row.Table;//.AsEnumerable();
            var billing = ((DataTable)((System.Web.UI.WebControls.GridView)(sender)).DataSource).AsEnumerable();
            var t = (from p in billing select p.Field<Double>("WO")).Sum();
            Label lblTotal = e.Row.FindControl("lblFooterWO") as Label;
            lblTotal.Text = t.ToString();
        }
    }

Thursday, May 17, 2012

LinkDataSource can't load DataContext

I was trying to populate a dropdown list control on an web page using VS 2008 and keep getting an error that it can't load the DataContext while using Dynamic Data while using it with linqdatasource.
issue i found was the use of DataContext without its namespace so when used with namespace it was resolved like

<asp:LinqDataSource ID="LinqDataSource1" runat="server"ContextTypeName="MyNameSpace.MyDataContext" TableName="MyTable"> </asp:LinqDataSource>

instead of

<asp:LinqDataSource ID="LinqDataSource1" runat="server"ContextTypeName="MyDataContext" TableName="MyTable"> </asp:LinqDataSource>

Wednesday, May 16, 2012

Post Xml Content to Blog

I had an issue while posting xml contents to blogs that contents were not appeared while viewing post
 so i used the encoding of html from the given site and it worked well for me.
http://centricle.com/tools/html-entities/

Data Triggers in WPF

I just once required to color a row of Gridview on the basis of associated data
i used RowLoaded event of the grid
and applied the foreground color by applying check on the associated property like
GridDemo.DummyModel model = (GridDemo.DummyModel)e.Row.DataContext;
 if (model.AutoAdvance == true)
    {
     e.Row.Foreground = new SolidColorBrush(Colors.Orange);
    }

But it was not sufficient to handle run time changes in the binding source so i used
DataTriggers in xaml like
   
        I just once required to color a row of Gridview on the basis of associated data
i used RowLoaded event of the grid
and applied the foreground color by applying check on the associated property like

GridDemo.DummyModel model = (GridDemo.DummyModel)e.Row.DataContext;
 if (model.AutoAdvance == true)
    {
     e.Row.Foreground = new SolidColorBrush(Colors.Orange);
    }


But it was not sufficient to handle run time changes in the binding source so i used
DataTriggers in xaml like
        <UserControl.Resources>
        <Style TargetType="telerik:GridViewRow">
            <Style.Triggers>
                <DataTrigger Binding="{Binding AutoAdvance}" Value="true">
                    <Setter Property="Foreground" Value="Orange"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Succeeded}" Value="true">
                    <Setter Property="Foreground" Value="Blue"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Failed}" Value="true">
                    <Setter Property="Foreground" Value="Red"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

which changed the Foreground color of row to orange when binding values of AutoAdvance property =true
   

which changed the Foreground color of row to orange when binding values of AutoAdvance property =true

Tuesday, May 15, 2012

Exception:Cannot Start your application.The Workgroup information file is missing or opened exclusively by another user

I ran into this issue while trying to connect a password protected Microsoft Access database.
here was my connection string
string conString =@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="Test.mdb";User Id=Admin;Password=123";

i resolved it by using Jet OLEDB:Database Password instead of Password and removing UserId
 like
string conString =@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="Test.mdb";Jet OLEDB:Database Password=123";

Friday, May 11, 2012

Invalid length for a Base-64 char array

I was having an issue while converting a cipher values to base64 string , it was working smooth ,suddenly it started throwing exception invalid length for a base-64 char array .
I was sending text from an android app and was converting in server app.
issue i found was while posting text to server + sign was converted into space " " , after converting back into "+" sign it worked for me , like
s=s.Replace(" ", "+");

thanks to post from Kiranpatils at
http://kiranpatils.wordpress.com/2008/03/13/invalid-length-for-a-base-64-char-arrayrijandelmanagedencryption/

Sunday, April 15, 2012

Enabling service meta data to be viewable

add Httpget and Httppost in protocols in configuration like

    
"<"configuration">"
    "<"system.web">"
    "<"webServices">"
        "<"protocols">"
            "<"add name="HttpGet"/">"
            "<"add name="HttpPost"/">"
        "<"/protocols">"
    "<"/webServices">"
    "<"/system.web">"
"<"/configuration">"

End Point not found

My friend was having the issue End point not found while try to open a wcf service in internet explorer ,
service was using webhttpbinding and json as a data transfer medium,
when ever tried to browse svc file it shows error , end point not found , no event entery .
i just find out somewhere that
"web" endpoint was exposed as a JSON endpoint. It was not compatible with WSDL.
so i tried to call a method and it worked fine , returned json response.

Thursday, April 5, 2012

Combine text files into one

Combine text files into one with single DOS command

 I found a DOS command to merge multiple files into one, making it much easier to sniff out bugs.
copy *.txt target.txt

Thursday, March 29, 2012

assigning port 80 on IIS7 to web site

i was having an issue while running a website on port 80, i stopped default web sites and changed their port to 8080 and assign port 80 to my website, but when tried to run the application it prompted that can not run file is being used by another application.
my web was running on every other port i assigned but not on 80.
so what i did was first to find which applicaion is using the port 80 in my system
by using the following command
netstat -ano
here i found that port 80 is being used by skype thats why my web was not running on port 80.
so just a simple solution then , turned off skype, or changed the port of skype other than 80 and it worked well

Monday, March 26, 2012

W3Wp is attached to which application pool IIS 7.0

often we need to know worker process (w3wp.exe) is attached to which application pool in IIS . in IIS 7 we can check it by
the following
Start > Run > Cmd
• Go To Windows > System32 > Inetsrv• Run appcmd list wp
i.e
c:\windows\system32\inetserv\appcmd.exe list wp

this will do the work and if we want them to export them in text file we can use

c:\windows\system32\inetserv\appcmd.exe list wp > wp.txt

Printing IIS 7.0 site collection information

I was asked to make a list of hosted applications on our amazone live server , so that we can perform some analysis on running application, hosted ports etc .
after looking into IIS 7.0 manager i found a summery view is available but not allowing it to copy or to print details , so what i found was
using inetsrv command and providing it a text file , this command\tool will list all sites into provided text file. command can be used like that

c:\windows\system32\inetsrv\> appcmd list sites > sitelist.txt

where sitelist.txt will be the file containing site information.

Note:file can pe placed commonly in system32 folder or C:\users\[yourusers] folder

Saturday, March 17, 2012

Handler "PageHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list

Got above issue when trying to run a simple asp.net application developed on visual studio 2010 for dot net framework 4 to be run on IIS7.
issue was resolved by installing asp.net for Framework 4.0 by using the command
aspnet_regiis -i
from the directory
C:\Windows\Microsoft.NET\Framework\v4.0.30319

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

Being new on IIS 7 i created a simple asp.net web site and deployed on IIS but against my expectaions of running it well, it comes with different sort of errors like corrupted configuration files etc
so i removed handlers , modules section from web.config file but then it came out the issue of mime types , handlers etc
after trying a lot of things including
registering asp.net user,giving rigts to iis_user to that particular web directory
and
After read serveral articles about this, I found that we can change overrideModeDefault from deny to allow both for handlers and modules in the %windir%\system32\inetsrv\config\applicationHost.config. Alternatively, We can use %windir%\system32\inetsrv\appcmd command to do the same thing, e.g: %windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/handlers.
But, I found another solution to this problem, which you don't need change the overrideModeDefault attribute of the system.webServer configuration section. When you enable IIS7 in the control panel, please choose the appropriate sections under Internet Information Services > World Wide Web Services > Application Development Features
 i finally solve the issue by turning on asp.net features for IIS from windows features.

Thursday, February 9, 2012

The web application you are attempting to access on this web server is currently unavailable

By looking into event viewer i came to know that it was an issue with aspnet account , it was not having read  permissions on global assemble cache.
Issue was Resolved by doing the following things
-Assignging permissions to aspnet account on Frame work and Temp directories in windows
-Assigning permissions to aspnet account on application deployed.
-Reinstalling aspnet user by aspnet_regiis -i for framework 2.0.