Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i want to add an id after localhost portnumber using rules in web.config

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'

like image 438
Syed Rasheed Avatar asked Nov 19 '15 06:11

Syed Rasheed


1 Answers

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>
like image 50
Syed Rasheed Avatar answered Sep 30 '22 03:09

Syed Rasheed