Web服务返回“301错误永久移动”在生产环境中 [英] Web service returns "301 error moved permanently" in production environment

查看:355
本文介绍了Web服务返回“301错误永久移动”在生产环境中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery调用一个Web服务,我有一个非常奇怪的问题,我整个上午都遇到了问题。当我在开发环境中调用Web服务时,一切都运行良好。投入生产后,我从Firebug获得301 Moved Permanently 38ms。

I am calling a web service using jQuery, and I have a very strange problem i've had problems with all morning. When I call the web service in my development environment, everything works perfectly. When put into production, I get an "301 Moved Permanently 38ms" from Firebug.

我的脚本是这样的:

 var data = '{"product":"' + productName + '", "from":"' + from + '", "question":"' +     question + '", "phone":"' + phone + '", "type":"' + typeOfMail + '"}';
$.ajax({
    type: "POST",
    datatype: "json",
    data: data,
    url: '<%= Page.ResolveUrl("~/Services/MailService.asmx/SendProductEmail") %>',
    contentType: "application/json; charset=utf-8",
    success: function (data) {
        resetContactControls();
        $('#<%=AskQuestionProductBtn.ClientID %>').hide();
    },
    failure: function (data) {
    }
});

这将编译为生产中的以下网址:

This compiles to the following URL in production:

url: '/Services/MailService.asmx/SendProductEmail'

在我的生产环境中,使用Firebug,我可以看到它尝试访问我的网址:

In my production environment, with Firebug I can see it tries to reach my URL:

http://www.hcemballering.dk/Services/MailService.asmx/SendProductEmail

手动尝试打开此URL时,我点击了我的网络服务。我也尝试更改网址,所以它只使用正常的../Services/MailService.asmx/SendProductEmail。

When manually trying to open this URL, I hit my webservice. I've also tried changing the url so it just uses the normal ../Services/MailService.asmx/SendProductEmail .

我也试过看看我的安全性设置,它应该工作(所有进程都有访问权限)。我甚至试图让用户Everyone完全访问服务,所以这应该不是问题。

I've also tried to look at my security settings, and it should work (all processes have access). I even tried to give the user "Everyone" full access to "Services", so it shouldn't be the problem.

这是我的Web服务类:

This is my web service class:

[ScriptService]
public class MailService : System.Web.Services.WebService {

    ILog logger = LogManager.GetLogger(typeof(MailService));

    [WebMethod]
    public bool SendProductEmail(string product, string from, string question, string phone, string type)
    {
        try
        {

            StringBuilder content = new StringBuilder();

            content.AppendLine(
                string.Format(
                    "Produkt:<br/>{0}<br/><br/>Fra email:<br/>{1}<br/><br/>Telefon:<br/>{2}<br/><br/>Type af henvendelse:<br/>{3}<br/><br/>Spørgsmål:<br/>{4}",
                    product, from, phone, type, question));
            var module = new MailModule(content.ToString(), "Kontakt om HC produkt: " + product);
            module.SendMail();
        }
        catch (Exception exp)
        {

            throw new Exception("Mailen blev desværre ikke sendt, da der skete en fejl");
        }


        return true;
    }

}

任何想法?

推荐答案

好的,这很傻。

这是由我的规则引起的web.config中。我有以下规则:

This was caused by a rule in my web.config. I had the following rule:

  <rule name="LowerCaseRule1" stopProcessing="true">
          <match url="[A-Z]" ignoreCase="false"/>

          <action type="Redirect" url="{ToLower:{URL}}"/>
        </rule>

当然,我的网址并非小写。所以我这样做了:

And of course, my URL wasn't lower case. So I did this:

 <rule name="LowerCaseRule1" stopProcessing="true">
          <match url="[A-Z]" ignoreCase="false"/>
          <conditions>
            <add input="{URL}" matchType="Pattern" pattern="^.+\.((axd)|(js)|(xaml)|(asmx))$" ignoreCase="true" negate="true"/>
          </conditions>
          <action type="Redirect" url="{ToLower:{URL}}"/>
        </rule>

并且还将所有内容都设为小写,只因为它的风格很好。

And also made everything lowercase, just because it's good style anyway.

它有效!

这篇关于Web服务返回“301错误永久移动”在生产环境中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆