301重定向与状态消息 [英] 301 redirection with status message

查看:72
本文介绍了301重定向与状态消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的项目是MVC C#和sitecore。如果网址不包含https://www.mysite.com,我需要实施301重定向。如果URL不包含此域url,那么我需要使用secure和www url重定向。它应该在控制台中显示。我该怎么做。我使用jquery完成了它,但它没有在浏览器的控制台中显示301重定向消息。





请帮助我。



我尝试了什么:



Global.asax正在减速和重定向http的网站的每个链接,所以它不显示网站的图像。

jquery工作正常,但没有显示301消息。

解决方案

从不使用javascript做任何安全相关的事情。另外你为什么要在控制台中看到一些东西?无论如何,您通常使用服务器端代码处理此问题。想要做的就是修改httpRequestBegin管道并注入自己的步骤。创建一个名为HttpsRedirector的类



 使用 Sitecore.Pipelines.HttpRequest; 

namespace YourNamespace.httpRequestBegin
{
public class HttpsRedirector:HttpRequestProcessor
{
public 覆盖 void 进程(HttpRequestArgs args)
{
// 可能希望在此添加一些逻辑以忽略某些网址

如果 (!args.Context.Request.IsSecureConnection)
{
string url = string .Format( https:// {0} {1},args.Context.Request .Url.Authority,args.Context.Request.RawUrl);

Sitecore.Diagnostics.Log.Info( string .Format( < span class =code-string>重定向到'{0}'的安全连接,url), this );
args.Context.Response.RedirectPermanent(url);
args.AbortPipeline();
}
}
}
}





在创建配置文件 App_Config /包含名为httpRequestBegin.config的文件夹(你的名字并不重要)



 <   configuration     xmlns :patch   =  http://www.sitecore.net/xmlconfig/ < span class =code-keyword>>  
< sitecore >
< pipelines >
< httpRequestBegin >
< processor 类型 = YourNamespace.HttpsRedirector,YourAssemblyName patch:before = * [@ type ='Sitecore.Pipelines.HttpRequest.ItemResolver,Sitecore.Kernel'] / >
< / httpRequestBegin >
< / pipelines >
< / sitecore >
< / configuration >


Hi,

My project is in MVC C# and sitecore. I need to implement 301 redirect if url doesn't contain https://www.mysite.com. If URL doesn't contain this domain url then I need to redirect with secure and www url. It should show in console. How can I do it. I have done it using jquery but it is not showing 301 redirect message in console of browser.


Please help me.

What I have tried:

Global.asax is making side slow and redirect every link of site on http so it is not showing images of site.
jquery working fine but not showing 301 message.

解决方案

Never do anything security related using javascript. Also why do you want to see something in the console? Anyway, you normally handle this using server-side code. Want you want to do is modify the httpRequestBegin pipeline and inject your own step. Create a class called HttpsRedirector

using Sitecore.Pipelines.HttpRequest;

namespace YourNamespace.httpRequestBegin
{
    public class HttpsRedirector : HttpRequestProcessor
    {
        public override void Process(HttpRequestArgs args)
        {
            // might want to add some logic here to ignore certain urls

            if (!args.Context.Request.IsSecureConnection)
            {
                string url = string.Format("https://{0}{1}", args.Context.Request.Url.Authority, args.Context.Request.RawUrl);

                Sitecore.Diagnostics.Log.Info(string.Format("Redirecting to secure connection for '{0}'", url), this);
                args.Context.Response.RedirectPermanent(url);
                args.AbortPipeline();
            }
        }
    }
}



Create a config file in the "App_Config/Include" folder called httpRequestBegin.config (doesn't really matter what you call it)

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <httpRequestBegin>
        <processor type="YourNamespace.HttpsRedirector, YourAssemblyName" patch:before="*[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/>
      </httpRequestBegin>
    </pipelines>
  </sitecore>
</configuration>


这篇关于301重定向与状态消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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