[英]In C#, how can I make it so it ends .aspx like a directory? Like file.aspx/programtorun/
所以我一直在使用php,并且因为喜欢它而切换到ASP.NET。 无论如何...我一直在开发自己的网站,但我无法终生解决!
我有的:
string val = HttpContext.Current.Request["Header"];
// filename: index.aspx
// what I need to get
if (val == "random")
{
renderA.Random("randoms.html");
}
else
{
renderA.Index("index.html");
}
它在URI中返回的内容
/index.asp?random
我希望它看起来像:
/index.aspx/random/
有办法解决这个问题吗?
您应该考虑切换到MVC站点。 它会为您提供所需的功能。
这是从较旧的版本中获得的,但是您会明白的: Scott Guthrie在谈论mvc框架
我假设您使用的是WebForms,而不是MVC。 它被称为FriendlyUrls,这是Hanselman的教程。 您可能要考虑切换到MVC,因为它可以使用Routing来完成 。
将Global Application Class
添加到您的项目(Global.asax文件),然后可以执行以下操作:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("random", "random", "~/index.html");
}
您将需要对System.Web.Routing
的引用
<%@ Import Namespace="System.Web.Routing" %>
学到更多:
http://msdn.microsoft.com/en-us/library/cc668201.ASPX
http://www.codeproject.com/Articles/77199/URL-Routing-with-ASP-NET-4-0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.