在ASP.NET MVC应用程序中从URL中删除应用程序名称 [英] Remove application name from url in ASP.NET MVC application
问题描述
在我的开发环境中
Url.Action(Index,User)---& / user
在生产环境中,应用程序在名为ucms的应用程序下配置
Url.Action(Index,User)---> / ucms / User
我有授权根据url ie,/ user,生产环境。如何解决此问题以删除ucms?
编辑
路由是默认的。 FYI,我已将应用程序从mvc 3.0升级到4.0。
routes.IgnoreRoute({resource} .axd / {* pathInfo});
routes.MapRoute(
Default,//路由名称
{controller} / {action} / {id},//带参数的URL
new {controller =Home,action =Index,id = UrlParameter.Optional} //参数默认值
);
编辑
我想出了一种方法
$ b< add key =appvirtualpathvalue =〜/ ucms/>
在将url传递到数据库层时,
Url.Action(Index,User)Replace(ConfigurationManager.AppSettings [appvirtualpath ] .ToString(),
〜);
右键单击项目,属性,web然后虚拟路径。
我不知道是否有在生产环境中配置它的方法。
In my development environment
Url.Action("Index", "User") ---> /user
In production, the application is configured under a application named "ucms"
Url.Action("Index", "User") ---> /ucms/User
I have authorization based on the url i.e., /user, so it is failing in production environment. How do I fix this issue to remove ucms?
Edit Routes are default one's. FYI, I've upgraded application from mvc 3.0 to 4.0.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Edit I have figured out one way to do it, could anyone share thoughts on this.
Store the virtual path in web.config.
<add key="appvirtualpath" value="~/ucms"/>
And while passing the url to the database layer, I would replace the virtual path will blank.
Url.Action("Index","User").Replace(ConfigurationManager.AppSettings["appvirtualpath"].ToString(), "~");
I solved this problem by adding a virtual path in development environment
Right click on project, properties, web and then virtual path.
I don't know if there is a way to configure it in the production environment
这篇关于在ASP.NET MVC应用程序中从URL中删除应用程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!