Note that there are some explanatory texts on larger screens.

plurals
  1. POPostback problem when using URL Rewrite and 404.aspx
    primarykey
    data
    text
    <p>I'm using URL rewrite on my site to get URLs like:<br> <em><a href="http://mysite.com/users/john" rel="nofollow noreferrer">http://mysite.com/users/john</a></em><br> instead of<br> <em><a href="http://mysite.com/index.aspx?user=john" rel="nofollow noreferrer">http://mysite.com/index.aspx?user=john</a></em></p> <p>To achive this extensionless rewrite with IIS6 and no access to the hosting-server I use the "404-approach". When a request that the server can't find, the mapped 404-page is executed, since this is a aspx-page the rewrite can be performed (I can setup the 404-mapping using the controlpanel on the hosting-service).</p> <p>This is the code in Global.asax:</p> <pre><code>protected void Application_BeginRequest(object sender, EventArgs e) { string url = HttpContext.Current.Request.Url.AbsolutePath; if (url.Contains("404.aspx")) { string[] urlInfo404 = Request.Url.Query.ToString().Split(';'); if (urlInfo404.Length &gt; 1) { string requestURL = urlInfo404[1]; if (requestURL.Contains("/users/")) { HttpContext.Current.RewritePath("~/index.aspx?user=" + GetPageID(requestURL)); StoreRequestURL(requestURL); } else if (requestURL.Contains("/picture/")) { HttpContext.Current.RewritePath("~/showPicture.aspx?pictureID=" + GetPageID(requestURL)); StoreRequestURL(requestURL); } } } } private void StoreRequestURL(string url) { url = url.Replace("http://", ""); url = url.Substring(url.IndexOf("/")); HttpContext.Current.Items["VirtualUrl"] = url; } private string GetPageID(string requestURL) { int idx = requestURL.LastIndexOf("/"); string id = requestURL.Substring(idx + 1); id = id.Replace(".aspx", ""); //Only needed when testing without the 404-approach return id; } </code></pre> <p>And in Page_Load on my masterpage I set the correct URL in the action-attribute on the form-tag.</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { string virtualURL = (string)HttpContext.Current.Items["VirtualUrl"]; if (!String.IsNullOrEmpty(virtualURL)) { form1.Action = virtualURL; } } </code></pre> <p>The rewrite works fine but when I perform a postback on the page the postback isn't executed, can this be solved somehow?</p> <p>The problem seems to be with the 404-approach because when I try without it (and loses the extensionless-feature) the postback works. That is when I request:<br> <em><a href="http://mysite.com/users/john.aspx" rel="nofollow noreferrer">http://mysite.com/users/john.aspx</a></em> </p> <p>Can this be solved or is there any other solution that fulfil my requirements (IIS6, no serveraccess/ISAPI-filter and extensionless).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload