0
URLを書き換えて、アドレスバーにsubdomain.example.com/blogのようなパスを表示しますが、www.example.com/blog/?tag=のようなページを表示するにはどうすればよいですか? /サブドメイン。URL書き換えC#.net
最初:ここ
は、私が発生するイベントの過程で、私は第二 をsubdomain.example.com/blogに移動します。私はwww.example.com/blog/?tag=/にリダイレクトしていますサブドメイン 第3:アドレスバーのURLは、サブドメイン.example.com/blogを表示しますが、 私はwww.example.com/blog/?tag=/subdomainページにいます。私は成功ここ
なしのIHttpModuleでこれをコーディングしようとしているHttpContext.RewritePath()メソッド
を使用することを好む私のコードです:
using System;
using System.Web;
using System.Net;
using System.Text;
using System.IO;
namespace CommonRewriter
{
public class ParseUrl : IHttpModule
{
public ParseUrl()
{
}
string req = null;
string rep = null;
public String ModuleName
{
get { return "CommonRewriter"; }
}
public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(application_BeginRequest);
application.EndRequest += new EventHandler(application_EndRequest);
application.PreRequestHandlerExecute += new EventHandler(application_PreRequestHandlerExecute);
application.AuthorizeRequest += new EventHandler(application_AuthorizeRequest);
}
void application_AuthorizeRequest(object sender, EventArgs e)
{
}
void application_PreRequestHandlerExecute(object sender, EventArgs e)
{
}
private string ParseAndReapply(string textToParse)
{
string final = null;
if (textToParse.Contains("example.com"))
{
string[] splitter = textToParse.Split('.');
if (splitter[0].ToLower() != "www" && (splitter[2].ToLower()).Contains("blog"))
{
string add = splitter[0].Remove(0, 7);
final = ("http://www.example.com/blog/?tag=/" + add);
}
else { final = textToParse; }
}
else { final = textToParse; }
return final;
}
void application_BeginRequest(object sender, EventArgs e)
{
req = HttpContext.Current.Request.Url.AbsoluteUri;
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
if (req.ToLower().Contains("example.com/blog") && !req.ToLower().Contains("www."))
{
string[] split = req.Split('.');
if (split[1] == "example")
{
rep = ParseAndReapply(req);
context.RewritePath(rep);
context.Response.End();
}
}
}
void application_EndRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
HttpContext context1 = HttpContext.Current;
if (HttpContext.Current.Request.Url.AbsoluteUri.Contains("/?tag=/"))
{
context.RewritePath(req,false);
}
}
}
public void Dispose() { }
}
}
私は試しましたが動作しません。 – user796762
少し具体的にすることができますか? URL書き換え拡張機能を使用するとどうなりますか? –
すべてが正しく動作するように設定されています。正しいパターンを使用してテストしますが、URLまたはリダイレクトを書き換えません。 – user796762