Redirect Web Page Requests to a Default Sub Folder

有些话、适合烂在心里 提交于 2019-12-25 05:28:29

问题


I am using UltiDev Web Server Pro and have all my aspx files are located in a sub folder 'WebForms'.

I want to be able to default all requests for pages to this folder such that they can just type: http://myserver/somepage.aspx instead of

http://myserver/WebForms/somepage.aspx.

Is this possible?

EDIT:

Here is the VB.NET version of the solution below including a check for case sensitivity:

If Not HttpContext.Current.Request.Path.ToUpper.Contains("/WEBFORMS/") Then
    Context.RewritePath("/WebForms" + HttpContext.Current.Request.Path, False)
End If

回答1:


You can use the Global.asax and the Application_BeginRequest to RewritePath to the final destination and still have the link without the WebForm path.

protected void Application_BeginRequest(Object sender, EventArgs e)
{   
    if(!HttpContext.Current.Request.Path.Contain("/WebForms/"))
       RewritePath("/WebForms" + HttpContext.Current.Request.Path, false);  
}


来源:https://stackoverflow.com/questions/11393441/redirect-web-page-requests-to-a-default-sub-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!