重写URL在ASP C# [英] Rewrite URL in asp c#

查看:90
本文介绍了重写URL在ASP C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何重定向基于C#.NET或asp.net 4.0寄存器客户端上的URL。例如,如果客户端注册为CLIENT1和我们的网站是www.mycompany.com每一页客户收益应该得到www.client1.mycompany.com。

更详细的例子:

例如创建了另一个客户端是客户端2。我已经在一般创建的网页就像

 www.mycompany.com/product.aspx
 www.mycompany.com/categories.aspx应显示为
 www.client2.mycompany.com/product.aspx和
 www.client2.mycompany.com/categories.aspx

分别
我会搜索网页,发现静态页面或应用程序的启动过程中使用Gloabal.asax但没有发现任何东西的用户登录后。


解决方案

  // DLL:Intelligencia.UrlRewriter.dll    //web.config
    <结构>      < configSections>
        <节名称=重写requirePermission =假TYPE =Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler,Intelligencia.UrlRewriter/>
      < / configSections>
    < /结构>    <&的System.Web GT;
        <&的HttpModules GT;
          <添加名称=UrlRewriterTYPE =Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter/>
        < /&的HttpModules GT;
    < /system.web>
    <&着意GT;
        <重写URL =〜/(.+)/ CompanyHomePage为=〜/ Home.aspx/>
    < /重写>
    //C#:     字符串strTitle =会话[COMPANY_NAME]的ToString()。
     strTitle = strTitle.Trim(' - ');
     strTitle = strTitle.ToLower();
     的char []字符= @。!?$%#@ *;:〜`+ =()[] {} | \\'<>,/ ^&放;ToCharArray();
     strTitle = strTitle.Replace(C#,C-夏普);
     strTitle = strTitle.Replace(vb.net,VB-网);
     strTitle = strTitle.Replace(asp.net,ASP-网);
     strTitle = strTitle.Replace( - ,。);    的for(int i = 0; I< chars.Length;我++)
    {
        字符串strChar = chars.GetValue(I)的ToString();
        如果(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); //重定向到〜/ Home.aspx页
//参考:在web.config中&LT CompanyHomePage一样;重写URL =〜/(.+)/ CompanyHomePage为=〜/ Home.aspx/>哪家公司登录到眼前的景象公司名称显示在URL这样的http:// // ABCD CompanyHomePage

How do I redirect url based on register client in c# .net or asp.net 4.0. For example if client registers as "client1" and our website is www.mycompany.com for every page client proceeds should get www.client1.mycompany.com.

More detailed example:

For example another client created is Client2. The pages i have created in general is like

 "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"

respectively I have searched on web and found for static pages or using Gloabal.asax during startup of application but haven't found any thing after user logged in.

解决方案

    //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

这篇关于重写URL在ASP C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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