2011-09-15 194 views
0

我在命令行應用程序中使用WebServiceHost。我想做一些與我從Web應用程序中獲得的片段相同的內容。有任何想法嗎 ?如何攔截webservicehost的請求

protected void Application_BeginRequest(object sender, EventArgs e) 
{ 
    EnableCrossDomainAjaxCall(); 
} 

private void EnableCrossDomainAjaxCall() 
{ 
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); 

    if (HttpContext.Current.Request.HttpMethod == "OPTIONS") 
    { 
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST"); 
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept"); 
    HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000"); 
    HttpContext.Current.Response.End(); 
    } 
} 

回答