How to hide page name and query string in ASP.NET?

I want to set Masking URL in asp.net to hide the page name and query string in the URL.

I am currently installing the code below to do a URL rewrite in the Global Application File.

routeCollection.MapPageRoute("Login", "Login", "~/frmLogin.aspx");

But I want to rewrite the URL so that it only displays the domain name for the end user. http://www.domainname.com - like this

Please help me install it.

Thanks in advance,

+4
source share
6 answers

You can set the frmLogin.aspx page as the default page on the web server.

If you are using IIS 7, the following steps:

 1.Select your website
 2. In description click on default document
 3. Add your page (frmLogin.aspx) in and set its priority.
+3
source

. .

Global.asax:

routeCollection.MapPageRoute("SIGNIN", String.Empty, "~/signin.aspx");
+2

, , .

+1

. , .

www.domainname.com, www.domainname.com/default.aspx , . say 'pagetoview', , server.transfer .

, form.aspx ' . load.aspx pagetoview, , else, pagetoview .

server.transfer. , .

+1

asp.net cookie . aspx default.aspx , . script default.aspx:

<script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
<script>
    $(document).ready(function () {
        $("a").click(function (e) {
            e.preventDefault();
            var attrHref = $(this).attr("href");
            $.getJSON("/service.asmx/SetRouteCookie", { href: attrHref }, function (e) {
                window.location.reload();
            });
        });
    });
</script>

script , click . click - ajax. cookie :

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json, XmlSerializeString = false, UseHttpGet = true)]
    public void SetRouteCookie()
    {
        if (HttpContext.Current.Request.QueryString["href"] != null)
        {
            string href = HttpContext.Current.Request.QueryString["href"];
            HttpCookie c = new HttpCookie("CurrentRoute", href);
            c.Expires = DateTime.Now.AddHours(1);
            HttpContext.Current.Response.Cookies.Add(c);

            HttpContext.Current.Response.ContentType = "application/json";
            HttpContext.Current.Response.Write("{\"status\":\"ok\"}");

        }
    }

cookie javascript. Page_Load :

protected void Page_Load(object sender, EventArgs e)
    {
        #region process route

        if (HttpContext.Current.Request.Cookies["CurrentRoute"] != null)
        {
            var route = HttpContext.Current.Request.Cookies["CurrentRoute"].Value.ToString();
            string pageName = GetPageName(route);
            Placeholder1.Controls.Add(LoadControl("/ctrls/" + pageName + ".ascx"));
        }
        else
        {
            Placeholder1.Controls.Add(LoadControl("/ctrls/default.ascx"));
        }

        #endregion

    }

    public string GetPageName(string href)
    {
        int index = href.IndexOf("&");
        if (index == -1)
            return href.Trim('/');
        else
        {
            return href.Substring(0, index).Trim('/');
        }
    }

git: HideRoute

+1

Server.Transfer , asp.net default.aspx :

 Server.Transfer("/login.aspx?q1=testQuery");

url , login.aspx

+1

All Articles