有时项目app和m 需要公用一套接口 这个时候就要用到跨域:特别是app接口跨域访问站点时。
跨域配置:
1.iis服务器上需要安装URLwrite2.0
2.web.config 需要添加这个配置;
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="false" />
<staticContent>
<mimeMap fileExtension=".apk" mimeType="application/vnd.android.package-archive" />
<mimeMap fileExtension=".plist" mimeType="application/xml" />
<mimeMap fileExtension=".ipa" mimeType="application/octet-stream.ipa"/>
</staticContent>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin,Content-Type,api_key,Authorization,appauthorizetoken,appsessionid,client,accept,key" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
</customHeaders>
</httpProtocol>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
3.Global.asax 添加 options 配置
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Context.Request.HttpMethod.ToLower() == "options")
{
Context.Response.End();
}
}