405: 方法不允许
编辑:摘要:似乎我的网络应用程序可以由任何人(仅限 Firefox 或 chrome)和我使用我的主计算机访问。如果我尝试从我的任何其他 LAN 访问 http://luiscarlosch.com/WebFormClean.aspx收到 405 错误
我可以从本地主机完美调用 WCF Web 方法。我发布到此服务器: http://luiscarlosch.com/WebFormClean.aspx (仅限 Firefox 或 chrome) 使用 Visual Studio 发布工具,效果很好。问题是当尝试从另一台计算机访问它时。我收到 405:方法不允许。 但这没有意义,因为正如我所说,当我从发布者计算机远程访问它时它工作正常。 有什么想法吗?
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ContactProxy
{
[WebGet()]
[OperationContract]
public Contact getByID(int IDContact)
{
Contact contact = new Contact(IDContact);
return contact;
}
[OperationContract]
public EntityData insertEntityData(int IDEntityDataFieldType, int IDContact, String value)
{
//Contact contact = new Contact();
// contact.insertEntityData(IDEntityDataFieldType, IDContact, value);
EntityData entityData = new EntityData();
entityData.save(IDEntityDataFieldType, IDContact, value);
return entityData;
}
}
这两种方法似乎都不起作用。
我刚刚注意到一些用户能够访问 http://luiscarlosch.com/WebFormClean.aspx 因为他们改变了价值观。所以。有些客户可以读取这些方法,但有些则不能。这应该会发生。
网页配置
<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebApplicationTest.WCFProxy.EmployeeProxyAspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="WebApplicationTest.WCFProxy.EntityDataFieldCollectionProxyAspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="WebApplicationTest.WCFProxy.Service1AspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="WebApplicationTest.WCFProxy.ContactProxyAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="WebApplicationTest.WCFProxy.EmployeeProxy" behaviorConfiguration="MyServiceTypeBehaviors" >
<endpoint address="" behaviorConfiguration="WebApplicationTest.WCFProxy.EmployeeProxyAspNetAjaxBehavior"
binding="webHttpBinding" contract="WebApplicationTest.WCFProxy.EmployeeProxy" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
<service name="WebApplicationTest.WCFProxy.EntityDataFieldCollectionProxy" behaviorConfiguration="MyServiceTypeBehaviors" >
<endpoint address="" behaviorConfiguration="WebApplicationTest.WCFProxy.EntityDataFieldCollectionProxyAspNetAjaxBehavior"
binding="webHttpBinding" contract="WebApplicationTest.WCFProxy.EntityDataFieldCollectionProxy" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
<service name="WebApplicationTest.WCFProxy.Service1">
<endpoint address="" behaviorConfiguration="WebApplicationTest.WCFProxy.Service1AspNetAjaxBehavior"
binding="webHttpBinding" contract="WebApplicationTest.WCFProxy.Service1" />
</service>
<service name="WebApplicationTest.WCFProxy.ContactProxy" behaviorConfiguration="MyServiceTypeBehaviors" ><!--new-->
<endpoint address="" behaviorConfiguration="WebApplicationTest.WCFProxy.ContactProxyAspNetAjaxBehavior"
binding="webHttpBinding" contract="WebApplicationTest.WCFProxy.ContactProxy" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<bindings />
<client />
</system.serviceModel>
</configuration>
EDIT: Summary: It seems that my web app can be accessed by anyone (only firefox or chrome) and by me using my main computer. If i try to access http://luiscarlosch.com/WebFormClean.aspx from any other of my LAN it gets a 405 error
I can perfectly call a WCF web method from localhost. I published to this server: http://luiscarlosch.com/WebFormClean.aspx (only firefox or chrome)
with the Visual Studio publishing tool and it works fine. The problem is when a try to access it from another computer. I get the 405: Method Not Allowed.
But It doest make sense because It works fine when i access it remotely from the publisher computer as I said.
Any idea?
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ContactProxy
{
[WebGet()]
[OperationContract]
public Contact getByID(int IDContact)
{
Contact contact = new Contact(IDContact);
return contact;
}
[OperationContract]
public EntityData insertEntityData(int IDEntityDataFieldType, int IDContact, String value)
{
//Contact contact = new Contact();
// contact.insertEntityData(IDEntityDataFieldType, IDContact, value);
EntityData entityData = new EntityData();
entityData.save(IDEntityDataFieldType, IDContact, value);
return entityData;
}
}
Neither method seems to work.
I just noticed some user were able to access http://luiscarlosch.com/WebFormClean.aspx because they change the values. So. some clients can read the methods but some cant. This should be happening.
Web Config
<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebApplicationTest.WCFProxy.EmployeeProxyAspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="WebApplicationTest.WCFProxy.EntityDataFieldCollectionProxyAspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="WebApplicationTest.WCFProxy.Service1AspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="WebApplicationTest.WCFProxy.ContactProxyAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="WebApplicationTest.WCFProxy.EmployeeProxy" behaviorConfiguration="MyServiceTypeBehaviors" >
<endpoint address="" behaviorConfiguration="WebApplicationTest.WCFProxy.EmployeeProxyAspNetAjaxBehavior"
binding="webHttpBinding" contract="WebApplicationTest.WCFProxy.EmployeeProxy" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
<service name="WebApplicationTest.WCFProxy.EntityDataFieldCollectionProxy" behaviorConfiguration="MyServiceTypeBehaviors" >
<endpoint address="" behaviorConfiguration="WebApplicationTest.WCFProxy.EntityDataFieldCollectionProxyAspNetAjaxBehavior"
binding="webHttpBinding" contract="WebApplicationTest.WCFProxy.EntityDataFieldCollectionProxy" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
<service name="WebApplicationTest.WCFProxy.Service1">
<endpoint address="" behaviorConfiguration="WebApplicationTest.WCFProxy.Service1AspNetAjaxBehavior"
binding="webHttpBinding" contract="WebApplicationTest.WCFProxy.Service1" />
</service>
<service name="WebApplicationTest.WCFProxy.ContactProxy" behaviorConfiguration="MyServiceTypeBehaviors" ><!--new-->
<endpoint address="" behaviorConfiguration="WebApplicationTest.WCFProxy.ContactProxyAspNetAjaxBehavior"
binding="webHttpBinding" contract="WebApplicationTest.WCFProxy.ContactProxy" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<bindings />
<client />
</system.serviceModel>
</configuration>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了允许跨域 ajax 调用,您需要
1) 首先配置您的 Web 服务器以允许来源和标头
2) 允许用于发出请求的方法
看来您已经完成了第一点,也许第二点您只需要更改:
为:
In order to allow cross domain ajax call you need
1) first to configure your web server to allow origins and Headers
2) allow methods used to make the request
It's seems that you have accomplished the first point and maybe for the second you just need to change:
to:
您的服务中发生了一些奇怪的事情。首先,我认为
insertEntityDate
不应该是可调用的,因为它缺少WebGet
或WebInvoke
属性。另一个奇怪的事情是getById
被定义为WebGet
但它被称为 POST JSON 请求 - 我刚刚用 FireBug 和 Fiddler 检查了它:该服务对我有用,但它是与您向我们展示的合同中描述的服务不同。顺便提一句。如果您不打算使用 SOAP 端点,则没有理由启用 serviceMetadata 行为并添加 Mex 端点。
Something odd is happening in your service. First I think that
insertEntityDate
should not be callable because it is missingWebGet
orWebInvoke
attribute. Another strange thing is thatgetById
is defined asWebGet
but it is called as POST JSON request - I just checked it with FireBug and Fiddler:The service works for me but it is not the same service described by contract you have shown us. Btw. there is no reason to enable serviceMetadata behavior and add Mex endpoints if you are not going to use SOAP endpoint as well.
使用 CORS 时,规范要求浏览器“预检”请求,使用 HTTP OPTIONS 从服务器请求支持的方法,并且服务器发送 405 方法不允许响应,也指示允许的方法。
此响应的唯一目的是帮助您找出可用于特定 URL 资源的通信选项。允许客户端确定与资源或服务器的功能相关的选项和/或要求,而无需涉及数据传输的特定操作。
希望有帮助,
When using CORS the specification mandates that browsers "preflight" the request, soliciting supported methods from the server with an HTTP OPTIONS and the server sends a 405 method not allowed response, also indicating the allowed method.
The sole purpose of this response is to help you find out the communication options available for a particular URL resource. Allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without a specific action involving transfer of data.
Hope it helps,