URL Rewrite does not work RRS feed

  • Question

  • User-314484952 posted


    I had an old website with url domain.com/mobile. Now my new site is fluid with all devices. Therefore, domain.com/mobile has become to domain.com.

    I have added the following code to Global, but it does not redirect, running into server error 500.

    void Application_BeginRequest(object sender, EventArgs e)
    if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("/mobile"))
    HttpContext.Current.Response.Status = "301 Moved Permanently";
    HttpContext.Current.Response.RedirectPermanent(Request.Url.ToString().ToLower().Replace("/mobile", ""));

    Can anyone help me with this?

    Thank you.

    Thursday, March 26, 2020 2:55 AM

All replies

  • User-1330468790 posted

    Hi, ellawei33,


    Your code should be working for your purpose as it seems no error inside the code.

    I suggest you debug the code to find out more details about that 500 Internal Server Error.



    You can run your app in debug mode and check the property AllErrors.

    Open the Global.asax.cs and in the body of the class add method:

    protected void Application_EndRequest()
    {   // Add the breakpoint here
        // Right click and select quick watch and you will find the exceptions at code: this.Context.AllErrors
        // Or you can add the code here and directly check the value of AllErrors


    Moreover, if you could not find the error details from the browser, debug mode would be always helpful to find them since they tells what the exact  problem is.


    Hope this can help you.

    Best regards,


    Thursday, March 26, 2020 5:13 AM