Force IE7 Compatibility Mode in IE8

30. December 2009

Force IE8 into IE7 compatibility mode using a meta tag in the header. 

This tag needs to be first in the <head> (before any css):

<meta http-equiv="X-UA-Compatible" content="IE=7" />
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

 


IIS 6

Go to the website, bring up the properties for it, and click on the HTTP Headers tab.

 

image

 HTTP Headers tab of an IIS 6 Website

 

Then, add a new header as below:

imageAdd custom HTTP Header 

 

IIS 7

IIS 7 is much the same.  Just go to the site and click on “HTTP Response Headers”.

 

imageIIS 7 Website Properties – IIS Section 

Then, just add the header:

image Add custom HTTP Header 

Incidentally, this just sets a value in the web.config, as below:

 

image

More later - jv


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, Web.Config, HTML, IIS, IIS 6, IIS 7, TIPS , , , , ,

Json asp.net web services

26. December 2009

using System;

using System.Web;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Web.Script.Services;

using System.Collections.Generic;

using System.Linq;

 

public class Employee

{

    public string firstname;

    public string lastname;

    public int age;

   
}

 

/// <summary>

/// Summary description for Employeeservice

/// </summary>

 

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

 

[ScriptService]

public class Employeeservice : WebService

{

 

    List<Employee> Employees = new List<Employee>{

    new Employee{firstname="Aamir",lastname="Hasan",age=20},
    new Employee{firstname="awais",lastname="Hasan",age=50},
    new Employee{firstname="Bill",lastname="Hasan",age=70},
    new Employee{firstname="sobia",lastname="khan",age=80},


 
    };

 

    [WebMethod]

    public List<Employee> GetAllEmployees()

    {

        return Employees;

    }

 

 

    [WebMethod]

    public List<Employee> GetEmployeesByDoors(int doors)

    {

        var query = from c in Employees

                    where c.Doors == doors

                    select c;

        return query.ToList();

    }

}



<form id="form1" runat="server">

<input type="button" id="Button1" value="Get Employees" />

<div id="output"></div>

</form>

 

All that's needed now is some Javascript for the getEmployees() method that has been assigned to the onclick event of the html button. This will go into the <head> section of the page:

 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>

<script type="text/javascript">

 

  $(function() {

    $('#Button1').click(getEmployees);

  });

 

  function getEmployees() {

    $.ajax({

      type: "POST",

      url: "Employeeservice.asmx/GetAllEmployees",

      data: "{}",

      contentType: "application/json; charset=utf-8",

      dataType: "json",

      success: function(response) {

        var Employees = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;

        $('#output').empty();

        for (var i = 0; i < Employees.length; i++) {

          $('#output').append('<p><strong>' + Employees[i].lastname + ' ' +

                                Employees[i].firstname + '</strong><br /> Age: ' +

                                Employees[i].age + '<br />Doors: ' +

                             

                                 '</p>');

        }

      },

      failure: function(msg) {

        $('#output').text(msg);

      }

    });

  }

</script>


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

Ajax, ALL, asp.net, TIPS , ,

working of Global.asax file

26. December 2009

The Global.asax file, which is derived from the HttpApplication class, maintains a pool of HttpApplication objects, and assigns them to applications as needed. The Global.asax file contains the following events:

  • Application_Init: Fired when an application initializes or is first called. It's invoked for all HttpApplication object instances.
  • Application_Disposed: Fired just before an application is destroyed. This is the ideal location for cleaning up previously used resources.
  • Application_Error: Fired when an unhandled exception is encountered within the application.
  • Application_Start: Fired when the first instance of the HttpApplication class is created. It allows you to create objects that are accessible by all HttpApplication instances.
  • Application_End: Fired when the last instance of an HttpApplication class is destroyed. It's fired only once during an application's lifetime.
  • Application_BeginRequest: Fired when an application request is received. It's the first event fired for a request, which is often a page request (URL) that a user enters.
  • Application_EndRequest: The last event fired for an application request.
  • Application_PreRequestHandlerExecute: Fired before the ASP.NET page framework begins executing an event handler like a page or Web service.
  • Application_PostRequestHandlerExecute: Fired when the ASP.NET page framework is finished executing an event handler.
  • Applcation_PreSendRequestHeaders: Fired before the ASP.NET page framework sends HTTP headers to a requesting client (browser).
  • Application_PreSendContent: Fired before the ASP.NET page framework sends content to a requesting client (browser).
  • Application_AcquireRequestState: Fired when the ASP.NET page framework gets the current state (Session state) related to the current request.
  • Application_ReleaseRequestState: Fired when the ASP.NET page framework completes execution of all event handlers. This results in all state modules to save their current state data.
  • Application_ResolveRequestCache: Fired when the ASP.NET page framework completes an authorization request. It allows caching modules to serve the request from the cache, thus bypassing handler execution.
  • Application_UpdateRequestCache: Fired when the ASP.NET page framework completes handler execution to allow caching modules to store responses to be used to handle subsequent requests.
  • Application_AuthenticateRequest: Fired when the security module has established the current user's identity as valid. At this point, the user's credentials have been validated.
  • Application_AuthorizeRequest: Fired when the security module has verified that a user can access resources.
  • Session_Start: Fired when a new user visits the application Web site.
  • Session_End: Fired when a user's session times out, ends, or they leave the application Web site.

The event list may seem daunting, but it can be useful in various circumstances.

A key issue with taking advantage of the events is knowing the order in which they're triggered. The Application_Init and Application_Start events are fired once when the application is first started. Likewise, the Application_Disposed and Application_End are only fired once when the application terminates. In addition, the session-based events (Session_Start and Session_End) are only used when users enter and leave the site. The remaining events deal with application requests, and they're triggered in the following order:

  • Application_BeginRequest
  • Application_AuthenticateRequest
  • Application_AuthorizeRequest
  • Application_ResolveRequestCache
  • Application_AcquireRequestState
  • Application_PreRequestHandlerExecute
  • Application_PreSendRequestHeaders
  • Application_PreSendRequestContent
  • <<code is executed>>
  • Application_PostRequestHandlerExecute
  • Application_ReleaseRequestState
  • Application_UpdateRequestCache
  • Application_EndRequest

protected void Application_Start(Object sender, EventArgs e) {
Application["Title"] = "Studnetacad.com";
}
protected void Session_Start(Object sender, EventArgs e) {
Session["startValue"] = 0;
}
protected void Application_AuthenticateRequest(Object sender, EventArgs e) {
// Extract the forms authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if(null == authCookie) {
// There is no authentication cookie.
return;
}
FormsAuthenticationTicket authTicket = null;
try {
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
} catch(Exception ex) {
// Log exception details (omitted for simplicity)
return;
}
if (null == authTicket) {
// Cookie failed to decrypt.
return;
}
// When the ticket was created, the UserData property was assigned
// a pipe delimited string of role names.
string[2] roles
roles[0] = "aamir"
roles[1] = "hasan"
// Create an Identity object
FormsIdentity id = new FormsIdentity( authTicket );
// This principal will flow throughout the request.
GenericPrincipal principal = new GenericPrincipal(id, roles);
// Attach the new principal object to the current HttpContext object
Context.User = principal;
}
protected void Application_Error(Object sender, EventArgs e) {
Response.Write("Error encountered.");
}


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, Web.Config, asp.net 4.0, TIPS , ,

Change Visual Studio's default browser

24. December 2009

How to change Visual Studio's default browser.








Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, asp.net 4.0, TIPS , ,

Sending HTML Mail Using Gmail SMTP

22. December 2009
Sending HTML Mail Using Gmail SMTP

use namespace System.Net.Mail

 

    Sendmail();

       

        protected static bool Sendmail()
        {
            MailMessage MyMailMessage = new MailMessage();

            MyMailMessage.From = new MailAddress("xxx-xxx-xxx@gmail.com");

            MyMailMessage.To.Add("xxxxxx@gmail.com");

            MyMailMessage.Subject = "Feedback Form";

            MyMailMessage.IsBodyHtml = true;

            MyMailMessage.Body = "<table><tr><td>ggg</table></tr></td>";

            SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");

            SMTPServer.Port = 587;

            SMTPServer.Credentials = new System.Net.NetworkCredential("xxx-xxx-xxx@gmail.com", "zzzzzzz");

            SMTPServer.EnableSsl = true;

            try
            {

                SMTPServer.Send(MyMailMessage);


                return true;
            }

            catch
            {

                return false;


            }

 

posted by aamir Hasan



Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, CSharp, TIPS



User Name: Guest

Your Ip: 38.107.191.91
Time: