0

c#.netまたはasp.net4.0のレジスタクライアントに基づいてURLをリダイレクトするにはどうすればよいですか。たとえば、クライアントが「client1」として登録し、当社のWebサイトがすべてのページでwww.mycompany.comである場合、クライアントはwww.client1.mycompany.comを取得する必要があります。

より詳細な例:

たとえば、作成された別のクライアントはClient2です。私が一般的に作成したページは次のようなものです

 "www.mycompany.com/product.aspx" 
 "www.mycompany.com/categories.aspx" should be shown as
 "www.client2.mycompany.com/product.aspx" and
 "www.client2.mycompany.com/categories.aspx"

それぞれ、Webで検索し、アプリケーションの起動時に静的ページまたはGloabal.asaxを使用して検索しましたが、ユーザーがログインした後、何も見つかりませんでした。

4

3 に答える 3

2

これにはいくつかの方法があります。ub1k は一方通行で述べています。

最も簡単な方法は、global.aspx.cs を使用することだと思います (global.aspx がない場合は追加します)。

protected void Application_BeginRequest(object sender, EventArgs e)
{
    var currentPath = Request.Path.ToLower(); //get the request
    var myContext = HttpContext.Current;
    if (currentPath == "/addUser" || currentPath == "/newuser") //decide what to do with the request
        myContext.RewritePath("/login.ashx?path="+ currentPath);
     else  //default value
        myContext.RewritePath("/default.aspx");
}

簡単、明確、そして非常に強力な...

于 2013-02-27T09:27:39.083 に答える
1

クライアント ログインに基づいてリダイレクトを作成する場合 (これは内部アプリケーションの問題です (IIS URL リライターのように IIS では処理できません))、おそらくHttpModule.

したがって、あなたがすべきことは次のとおりです。

  • モジュールを作成 -> 実装するクラスIHttpModule
  • このモジュールでは、リダイレクト ロジックを実装します。
  • web.config セクションにプラグインします: 次<configuration><system.web><httpModules>のように:

    <add name="MyModule" type="MyModule.Module, MyModule" />

すべてはhttp://support.microsoft.com/kb/307996にあります。

after認証が完了したイベントにロジックをフックするように注意してください。また、ユーザー情報を読み取るには、モジュールも実装する必要があると思いますIRequiresSessionState

于 2013-02-27T08:45:41.280 に答える
-1
    //DLL: Intelligencia.UrlRewriter.dll    

    //web.config
    <configuration>

      <configSections>
        <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/>
      </configSections>
    </configuration>

    <system.web>
        <httpModules>
          <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
        </httpModules>
    </system.web>


    <rewriter>
        <rewrite url="~/(.+)/CompanyHomePage" to="~/Home.aspx"/>
    </rewriter>


    //C#:

     string strTitle = Session["company_name"].ToString();
     strTitle = strTitle.Trim('-');
     strTitle = strTitle.ToLower();
     char[] chars = @"$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray();
     strTitle = strTitle.Replace("c#", "C-Sharp");
     strTitle = strTitle.Replace("vb.net", "VB-Net");
     strTitle = strTitle.Replace("asp.net", "Asp-Net");
     strTitle = strTitle.Replace(".", "-");

    for (int i = 0; i < chars.Length; i++)
    {
        string strChar = chars.GetValue(i).ToString();
        if (strTitle.Contains(strChar))
        {
           strTitle = strTitle.Replace(strChar, string.Empty);
        }
    }
     strTitle = strTitle.Replace(" ", "-");
     strTitle = strTitle.Replace("--", "-");
     strTitle = strTitle.Replace("---", "-");
     strTitle = strTitle.Replace("----", "-");
     strTitle = strTitle.Replace("-----", "-");
     strTitle = strTitle.Replace("----", "-");
     strTitle = strTitle.Replace("---", "-");
     strTitle = strTitle.Replace("--", "-");
     strTitle = strTitle.Trim();
     strTitle = strTitle.Trim('-');

     Response.Redirect("~/" + strTitle + "/CompanyHomePage", false);//Redirect to ~/Home.aspx page


//reference: CompanyHomePage same in web.config  <rewrite url="~/(.+)/CompanyHomePage" to="~/Home.aspx"/> which company is log in to sight that company name show in url like this http://abcd//CompanyHomePage
于 2013-05-16T12:08:31.350 に答える