gpt4 book ai didi

.net - 405 : Method Not Allowed

转载 作者:行者123 更新时间:2023-12-04 16:01:55 34 4
gpt4 key购买 nike

编辑:摘要:似乎任何人(仅 firefox 或 chrome)和我使用我的主计算机都可以访问我的网络应用程序。如果我尝试访问 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因为他们改变了值(value)观。所以。有些客户可以阅读方法,但有些客户不能。这应该发生。

网页配置
<?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>

最佳答案

为了允许跨域ajax调用,您需要

1)首先配置您的网络服务器以允许来源和标题
2) 允许用于发出请求的方法

似乎您已经完成了第一点,也许对于第二点,您只需要更改:

[WebGet()]

到:
[WebInvoke(Method = "*")]
  • 因为尽管您执行了 POST 或 GET 请求。 Chrome 和 Firefox 总是发送 OPTIONS
  • 关于.net - 405 : Method Not Allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4892455/

    34 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com