how can I get url of page ASPNET C#

Discussion in 'ASP .Net' started by Dariusz Tomon, Feb 7, 2006.

  1. Hi

    How can I get url of page so taht I can pass it to string varaible.

    I have got several urls in my IIS under one folder. I want to have one
    default.aspx where code under it recognize which url is used by user and
    then display appropriate data to that url (one url is about fashion, other
    about law and so on). By means of recognition of url I can display
    appropriate banners for example.

    Regards

    Darek T
    Dariusz Tomon, Feb 7, 2006
    #1
    1. Advertising

  2. Have you looked at the Request.Url property? it has a lot of useful
    properties such as Request.Url.AbolustePath and Request.Url.Segments

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Dariusz Tomon" <> wrote in message
    news:uDqezx$...
    > Hi
    >
    > How can I get url of page so taht I can pass it to string varaible.
    >
    > I have got several urls in my IIS under one folder. I want to have one
    > default.aspx where code under it recognize which url is used by user and
    > then display appropriate data to that url (one url is about fashion, other
    > about law and so on). By means of recognition of url I can display
    > appropriate banners for example.
    >
    > Regards
    >
    > Darek T
    >
    Karl Seguin [MVP], Feb 7, 2006
    #2
    1. Advertising

  3. Dariusz Tomon

    DKode Guest

    I dont really understand your question here.

    Is each URL a different aspx page or do you use a query string to
    access the different pages?

    If each URL is a seperate aspx page, then you can use Request.Url to
    get information about the requested URL.

    If you use query strings, IE: (default.aspx?page=fashion) then you can
    use Request.QueryString to get the query string requested.
    DKode, Feb 7, 2006
    #3
  4. It's totaly unclear what you want
    Here is couple thing for you to look at ( I think one will help).

    1.Application_BeginRequest in Global.asax to get URL before any ASPX page
    gets it.
    2. HttpContext.RewritePath to modify URL before ASPX page gets it.
    3. Request.ServerVariables("HTTP_URL") to get requested URL


    George.



    "Dariusz Tomon" <> wrote in message
    news:uDqezx$...
    > Hi
    >
    > How can I get url of page so taht I can pass it to string varaible.
    >
    > I have got several urls in my IIS under one folder. I want to have one
    > default.aspx where code under it recognize which url is used by user and
    > then display appropriate data to that url (one url is about fashion, other
    > about law and so on). By means of recognition of url I can display
    > appropriate banners for example.
    >
    > Regards
    >
    > Darek T
    >
    George Ter-Saakov, Feb 7, 2006
    #4
  5. telling the truth it is complicated I cannot tell you how server recognize
    what content to run:

    1) Default.aspx is the same for two areas (fashion and furniture).

    Default.aspx:

    <%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false"
    Inherits="EuroDomWnetrze._Default" %>
    <%@ Register TagPrefix="euroc" TagName="HeaderControl"
    Src="WebControl/HeaderControl.ascx" %>
    <%@ Register TagPrefix="euroc" TagName="FooterContol"
    Src="WebControl/FooterContol.ascx" %>
    <%@ Register TagPrefix="euroc" TagName="MenuiControl"
    Src="WebControl/MenuiControl.ascx" %>
    <%@ Register TagPrefix="euroc" TagName="BoxyControl"
    Src="WebControl/BoxyControl.ascx" %>
    <%@ Register TagPrefix="euroc" TagName="LicznikControl"
    Src="WebControl/LicznikControl.ascx" %>
    <?xml version="1.0"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="pl">
    <head>
    <title>EuroAdres » Dom &amp; Wnetrze</title>
    <meta name="author" content="Mariusz Turczyniak Tomasz Sribniak" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <meta name="generator" content="WebSite PRO 4.3"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta name="CODE_LANGUAGE" content="C#"/>
    <meta name="vs_defaultClientScript" content="JavaScript"/>
    <meta name="vs_targetSchema"
    content="http://schemas.microsoft.com/intellisense/ie5"/>
    <link href="http://www.euroadres.pl/App.ico" rel="shortcut icon"
    type="image/x-icon"/>
    <link type="text/css" href="Css/Default.css" rel="stylesheet"
    title="Podstawowy wyglad"/>
    </head>
    <body>
    <div id="Strona">
    <euroc:LicznikControl id="LicznikControl1"
    runat="server"></euroc:LicznikControl>
    <euroc:HeaderControl id="HeaderControl1"
    runat="server"></euroc:HeaderControl>
    <div id="DivLewyBG">
    <euroc:MenuiControl id="MenuiControl1"
    runat="server"></euroc:MenuiControl>
    <euroc:BoxyControl id="BoxyControl1" runat="server"></euroc:BoxyControl>
    </div>
    <euroc:FooterContol id="FooterContol1"
    runat="server"></euroc:FooterContol>
    </div>
    </body>
    </html>

    <<<<<END>>>>>

    (There is nothing interesting in Default.aspx.cs

    THEN

    You can see line: <euroc:HeaderControl id="HeaderControl1"
    runat="server"></euroc:HeaderControl>
    So Default.aspx is using webcontrol called HeaderControl.ascx (code
    below):

    <<<START>>>

    <%@ Register TagPrefix="basic" Namespace="EuroAdresBasic"
    Assembly="EuroAdresBasic" %>
    <%@ Control Language="c#" AutoEventWireup="false"
    Codebehind="HeaderControl.ascx.cs"
    Inherits="EuroDomWnetrze.WebControl.HeaderControl"
    TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
    <div id="DivEuroAdresBaner" runat="server">
    <!-- EuroAdresBaner --></div>
    <div id="DivBalkaHeader" runat="server"></div>
    <div id="DivBaner" runat="server">
    <!-- Baner --></div>
    <div id="DivSerwis_" runat="server"><basic:eserwisycontrol
    id="ESerwisyControl1" runat="server"></basic:eserwisycontrol></div>

    <<<END>>>

    <<<CODE>>> - the class under webcontrol HeaderControl - called
    HeaderControl.ascx.cs

    <<<START>>>

    namespace EuroDomWnetrze.WebControl
    {
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    using EuroAdresBasic;
    /// <summary>
    /// Summary description for HeaderControl.
    /// </summary>
    public class HeaderControl : System.Web.UI.UserControl
    {
    /// <summary>

    /// Set url before setting banner
    /// </summary>
    public string UrlBaner
    {
    set {url = value;}
    }

    public string Naglowek
    {
    set
    {
    naglowek = value;

    if (value.Length > 0)
    doBaner();
    else
    doDefaultBaner();
    }
    }

    public int IdJezyk
    {
    set
    {
    idJezyk = value;
    if (idJezyk != 1)
    DivSerwis_.Controls.Clear();
    }
    }

    private int idJezyk = 1;
    private string naglowek = "";
    private string url;

    protected HtmlGenericControl DivEuroAdresBaner;
    protected HtmlGenericControl DivBaner;
    protected HtmlGenericControl DivSerwis_;
    protected EuroAdresBasic.ESerwisyControl ESerwisyControl1;
    protected EuroAdresBasic.EFlashControl EuroBaner;
    protected HtmlGenericControl DivBalkaHeader;

    protected HtmlGenericControl image;


    private void Page_Load(object sender, System.EventArgs e)
    {
    test.Service1 s = new test.Service1();
    if (!s.AAAA())
    Response.StatusCode = 404;

    Response.StatusCode = 404;
    EuroBaner = new EFlashControl("Img/All/naglowek.swf", "770", "119",
    "flashvars", getFlaszParam());
    DivEuroAdresBaner.Controls.Add(EuroBaner);

    if (Page.

    //DivBalkaHeader.Controls.Add(new EFlashControl("waluty_swf.swf", "770",
    "19","flashvars", "uerel=http://www.euroadres.pl/Waluty.aspx"));

    doDefaultBaner ();
    }

    private void doDefaultBaner ()
    {
    DivBaner.Controls.Add(new EFlashControl("Img/All/billboard_DW.swf",
    "770","200"));
    }
    private void doBaner ()
    {
    // DivBaner.Controls.Clear();
    //
    // if (!naglowek.EndsWith(".swf"))
    // {
    // HtmlImage img = new HtmlImage();
    // img.Style.Add("width","770px");
    // img.Style.Add("height","200px");
    // img.Src = "../images/loga/"+naglowek+"\"";
    // img.Alt = "baner";
    //
    // if (url != "")
    // {
    // HtmlAnchor link = new HtmlAnchor();
    // link.HRef = "http://" + url;
    // link.Target = "_blank";
    // link.Controls.Add(img);
    // DivBaner.Controls.Add(link);
    // }
    // else
    // DivBaner.Controls.Add(img);
    // }
    // else
    // {
    // if (url != "")
    // {
    // DivBaner.Controls.Add(new EFlashControl("images/loga/" + naglowek,
    "770","200", "flashvars", "uerel=http://"+url+"&okno=1"));
    // }
    // else
    // DivBaner.Controls.Add(new EFlashControl("images/loga/" + naglowek,
    "770","200"));
    // }
    }
    private string getFlaszParam ()
    {
    string flashParem = "data=";
    flashParem += DateTime.Now.ToLongDateString() + "&";
    flashParem += "linki=Polski*http://www.euroadres.pl/zmienjezyk.aspx*1|";
    flashParem += "English*http://www.euroadres.pl/zmienjezyk.aspx*2|";
    flashParem += "Francais*http://www.euroadres.pl/zmienjezyk.aspx*3|";
    flashParem += "Magyar*http://www.euroadres.pl/zmienjezyk.aspx*4|";
    flashParem += "???????*http://www.euroadres.pl/zmienjezyk.aspx*14|";
    flashParem += "&strona_startowa=default.aspx";
    flashParem += "&haslo="+ getTwojAdres();

    return flashParem;
    }

    private string getTwojAdres()
    {
    // using (System.IO.TextReader tr =
    // new
    System.IO.StreamReader(Server.MapPath(@"Xml\Tlumaczenia.xml"),System.Text.Encoding.UTF8))
    // {
    // System.Xml.XmlReader x = new System.Xml.XmlTextReader(tr);
    //
    // while(x.Read())
    // if (x.IsStartElement("tlumaczenia"))
    // while(x.Read())
    // {
    // if (x.IsStartElement("tlumaczenie"))
    // {
    // string at = x.GetAttribute("co");
    // if (at == "Twój europejski adres")
    // {
    // while(x.Read())
    // {
    // if (x.IsStartElement("fraza"))
    // {
    // int jez = int.Parse( x.GetAttribute("idjezyk"));
    // if (jez == idJezyk)
    // {
    // return x.ReadString();
    // }
    // }
    // }
    // }
    // }
    // }
    //
    // x.Close();
    // }
    return "Twój europejski adres";
    }
    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion
    }
    }

    <<<END>>>

    I wonder how this code could recognize or guess :) - what to display?

    The fact is that when you enter: http://www.domiwnetrze.com/ and
    http://www.modaistyl.com.pl/ you'll get the other content still based on the
    same default.aspx and even the same HeaderControl.ascx

    How to explain it?

    Best Regards

    Dariusz Tomon



    "DKode" <> wrote in message
    news:...
    >I dont really understand your question here.
    >
    > Is each URL a different aspx page or do you use a query string to
    > access the different pages?
    >
    > If each URL is a seperate aspx page, then you can use Request.Url to
    > get information about the requested URL.
    >
    > If you use query strings, IE: (default.aspx?page=fashion) then you can
    > use Request.QueryString to get the query string requested.
    >
    Dariusz Tomon, Feb 7, 2006
    #5
  6. This is called HOST you can get host information by
    Request.Url.Host or Request.ServerVarables("HTTP_HOST")


    George.



    "Dariusz Tomon" <> wrote in message news:...

    ......skipped.....
    >
    > The fact is that when you enter: http://www.domiwnetrze.com/ and
    > http://www.modaistyl.com.pl/ you'll get the other content still based on the
    > same default.aspx and even the same HeaderControl.ascx
    >
    > How to explain it?
    >
    > Best Regards
    >
    > Dariusz Tomon
    George Ter-Saakov, Feb 7, 2006
    #6
  7. thank you - I'll do that and let you know.

    D.T.

    "George Ter-Saakov" <> wrote in message
    news:%...
    > It's totaly unclear what you want
    > Here is couple thing for you to look at ( I think one will help).
    >
    > 1.Application_BeginRequest in Global.asax to get URL before any ASPX page
    > gets it.
    > 2. HttpContext.RewritePath to modify URL before ASPX page gets it.
    > 3. Request.ServerVariables("HTTP_URL") to get requested URL
    >
    >
    > George.
    >
    >
    >
    > "Dariusz Tomon" <> wrote in message
    > news:uDqezx$...
    >> Hi
    >>
    >> How can I get url of page so taht I can pass it to string varaible.
    >>
    >> I have got several urls in my IIS under one folder. I want to have one
    >> default.aspx where code under it recognize which url is used by user and
    >> then display appropriate data to that url (one url is about fashion,
    >> other about law and so on). By means of recognition of url I can display
    >> appropriate banners for example.
    >>
    >> Regards
    >>
    >> Darek T
    >>

    >
    >
    Dariusz Tomon, Feb 7, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon paugh
    Replies:
    1
    Views:
    697
  2. Gary Nelson

    Upgrade from aspnet 1.1 to aspnet 2.0

    Gary Nelson, Oct 14, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    478
    Gary Nelson
    Oct 14, 2005
  3. Replies:
    7
    Views:
    639
    Juan T. Llibre
    Mar 23, 2007
  4. Brian Schuth
    Replies:
    0
    Views:
    273
    Brian Schuth
    Sep 8, 2003
  5. Alfred Sehmueller
    Replies:
    0
    Views:
    260
    Alfred Sehmueller
    Feb 20, 2004
Loading...

Share This Page