this is my code
<rule name="adding Id after PortNumber" patternSyntax="Wildcard" stopProcessing="true">
        <match  url="(.*)" />
        <conditions>
          <add input="{HTTP_HOST}" pattern="{HTTP_HOST}/12312312" negate="true"/>
        </conditions>
        <action type="Redirect" url="{HTTP_HOST}/{R:1}"/>
      </rule>
this is my route.config
 public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
           "ApplicationRoute",
           "{appId}/{controller}/{action}/{id}",
           new { controller = "Account", action = "SignIn", id = UrlParameter.Optional },
           new {
               isValidAppId = new isValidAppId() 
           }
       );
    }
}
public class isValidAppId : IRouteConstraint
{
    public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
    {
        var isValid = false;
        if (values["appId"] != null && WebConfigurationManager.AppSettings["ModelApplicationId"] != null)
        {
            if (values["appId"].ToString() == WebConfigurationManager.AppSettings["ModelApplicationId"].ToString())
                return isValid = true;
        }
        // return true if this is a valid AppId
        return isValid;
    }
}
but when i run this i am getting the url path as 'http://localhost:49363/' but i want 'http://localhost:49363/12312312'
After doing some more R&D on this, Eventually i got the solution
 <rewrite>
  <rules>
<rule name="AppId" stopProcessing="true">
  <match url="^$" /> 
  <action type="Redirect" url="/12312312" redirectType="Permanent" />
</rule>
  </rules>
</rewrite>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With