坚持这个问题.我有一个包含2个项目的解决方案,其中一个是带有jquery ajax调用的普通旧html,而另一个是WCF服务.html页面将发出对WCF服务的ajax调用以获取json字符串并将其用于显示目的.
现在问题是每当我在调试模式下运行时,html页面和WCF都将以不同的端口启动.当我执行测试时(即在Firefox中调用类型= OPTIONS获得405 Method Not Allowed错误),这为我创建了一个跨源问题.我会在我的ajax脚本上检查调用方法,并且WCF服务是相同的(GET).
我搜索谷歌但发现要么我必须安装扩展程序或在IIS上执行一些配置,我发现这很麻烦,因为我正在做的事情很简单.下面是一个例子,我将在web.config中添加以下配置,但它不起作用:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="MobileService.webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="MobileService.SimpleMemberInfo" behaviorConfiguration="MyServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="MobileService.IMemberInfo" bindingConfiguration="crossDomain" behaviorConfiguration="MobileService.webHttpBehavior">
</endpoint>
</service>
</services>
</system.serviceModel>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
</customHeaders>
</httpProtocol>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
任何人都有任何想法摆脱这个恼人的问题?
编辑:只是添加,我正在使用与VS …
我们正在尝试使用Google Apps Activity API查找对Google云端硬盘中的文件所做的更改.我们能够成功访问谷歌驱动器API,但活动API正在抛出403禁止错误.
错误:
消息:Google.Apis.Requests.RequestError Forbidden [403] Errors [Message [Forbidden] Location [ - ] Reason [forbidden] Domain [global]] InnerException:Stacktrace:at Google.Apis.Requests.ClientServiceRequest`1.Execute()在c:\ code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis\Apis\Requests\ClientServiceRequest.cs:第102行在WorkPort.Business.Google.DriveRepo.d__11.MoveNext()
任何投入都会有很大的帮助.我无法找到很多关于此的文档.
更新:
我在下面发布了我的身份验证码.
private static async Task<AuthorizationCodeWebApp.AuthResult> GetCredentials(string userId)
{
System.IO.File.AppendAllText("D:\\GoogleApi\\Logs\\customlog.txt", "Inside GetCredentials" + Environment.NewLine);
try
{
ClientSecrets secrets = new ClientSecrets
{
ClientId = CLIENT_ID,
ClientSecret = CLIENT_SECRET
};
IDataStore credentialPersistanceStore = getPersistentCredentialStore();
IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(
new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = secrets,
DataStore = credentialPersistanceStore,
Scopes = new[] { DriveService.Scope.Drive, AppsactivityService.Scope.Activity,DriveService.Scope.DriveReadonly,DriveService.Scope.DriveMetadataReadonly}
});
var redirectUri = …Run Code Online (Sandbox Code Playgroud) 从2个不同的应用程序中,我能够发送交叉请求.虽然浏览器返回Cross-Origin错误,但我的服务器仍在接收并执行请求.例如,从远程站点,我可以调用跨域请求,
$.ajax({
xhrFields: {
withCredentials: true
},
data:{ my: 'a' },
url: 'http://MyApp/Page',
type: 'POST'
})
Run Code Online (Sandbox Code Playgroud)
我知道浏览器不会返回脚本响应,但我的服务器页面仍然执行.
假设一个无辜的用户登录了一个站点http://abc.com.此应用程序将接受插入记录的发布请求.当无辜的用户访问无辜的http://HackerSite.com时,http://HackerSite.com将能够通过Ajax 向http://abc.com发送POST请求.怎么避免这个?
我可以在SQL Server 2008中创建包含数据的DACPAC吗?
我的要求是生成数据库更改的增量脚本,我能使用BACPAC吗?
我试过读这个,但这没什么用处:
https://msdn.microsoft.com/en-us/library/jj860455(v=vs.103).aspx