asp.net-mvc – 我想使用web.config中的规则在localhost portnum
发布时间:2020-12-16 04:26:09 所属栏目:asp.Net 来源:网络整理
导读:这是我的代码 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="
这是我的代码
<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> 这是我的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; } } 但是,当我运行这个我得到的网址为’http://localhost:49363/‘,但我想’http://localhost:49363/12312312‘ 解决方法
在做了更多R& D之后,最终得到了解决方案
<rewrite> <rules> <rule name="AppId" stopProcessing="true"> <match url="^$" /> <action type="Redirect" url="/12312312" redirectType="Permanent" /> </rule> </rules> </rewrite> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- .net – Umbraco vs DotNetNuke:无法决定哪一个更合适
- .NET 下基于动态代理的 AOP 框架实现揭秘
- asp.net – IIS 7.0不允许下载MP4视频
- asp.net-mvc – ASP.NET MVC强类型部分视图,无法加载类型错
- asp.net C# config 自定义节点及自定义节点配置以独立文件存
- 如何使ASP.NET服务器控件获得最短的ID?
- asp.net – 如何避免刷新页面上的按钮事件
- asp.net – 使用Roslyn动态编译控制器
- asp.net-mvc – ASP.NET Azure 400错误请求不返回JSON数据
- 我可以使用owin和oauth提供商的asp.net会员资格吗?
推荐文章
站长推荐
- 如何在ASP.NET MVC 5.2.3应用程序的其他地方获取
- asp.net – 根据自己的主机Web API Windows服务验
- asp.net – IIS 7.5中的Windows身份验证因信任关
- asp.net-mvc-3 – MVC动作被调用两次?
- asp.net-mvc – Thunderdome MVC-为什么在MVC中使
- asp.net – .NET异常页面非人类可读
- asp.net – 使用AJAX填充下拉列表
- asp.net-mvc – 带有owin和Identity的城堡windso
- asp.net-mvc – Angularjs中每个视图应该有一个控
- asp.net-mvc – ASP.NET MVC角色授权
热点阅读