août
4
2007

ASP.NET AJAX and URL rewriting issue

If you are using URL rewriting you might know that you have to take care about the way you reference resources has written in the Scott Guthrie post; Tip/Trick: Url Rewriting with ASP.NET:

Handling CSS and Image Reference Correctly

One gotcha that people sometime run into when using Url Rewriting for the very first time is that they find that their image and CSS stylesheet references sometimes seem to stop working.  This is because they have relative references to these files within their HTML pages - and when you start to re-write URLs within an application you need to be aware that the browser will often be requesting files in different logical hierarchy levels than what is really stored on the server.

For example, if our /products.aspx page above had a relative reference to "logo.jpg" in the .aspx page, but was requested via the /products/books.aspx url, then the browser will send a request for /products/logo.jpg instead of /logo.jpg when it renders the page.  To reference this file correctly, make sure you root qualify CSS and Image references ("/style.css" instead of "style.css").  For ASP.NET controls, you can also use the ~ syntax to reference files from the root of the application (for example: <asp:image imageurl="~/images/logo.jpg" runat="server"/>

This is for sure also the case for javascript.

I am using the Request.PathInfo way described in Scott's post to rewrite one url on Tech Head Brothers. Everything works fine except that Sys.Services.AuthenticationService get confused about the rewriting of the URL and tries to post back on :

http://localhost:8080/Auteurs.aspx/laurent-kempe/Authentication_JSON_AppService.axd/Login

When I expect

http://localhost:8080/Authentication_JSON_AppService.axd/Login

Looking at the page rendered by ASP.NET I see that the following is rendered:

<script type="text/javascript">
<!--
Sys.Services._AuthenticationService.DefaultWebServicePath = 'Authentication_JSON_AppService.axd';
// -->
</script>

So I am clearly missing a / in the path and due to that the URL rewriting confuse the post to the server.

The first solution was found by Cyril Durand (always of good help in this AJAX world ;) and is to add this line of code:

ScriptManager.GetCurrent(Page).AuthenticationService.Path = "/Authentication_JSON_AppService.axd";

But I did it a bit differently, directly in the javascript adding the following line:

Sys.Services.AuthenticationService.set_path('/Authentication_JSON_AppService.axd');

Btw this javascript line would be generated at rendering time by the solution of Cyril.

Thanks Cyril for the always nice talks.

Commentaires (2) -

http://

rrr

http://

thx maaaaaaaaaaaaaaaaaaaan, that helps so much

Ajouter un commentaire

  Country flag

biuquote
  • Commentaire
  • Prévisualiser
Loading

About Laurent

Laurent Kempé

Laurent Kempé is the editor, founder, and primary contributor of Tech Head Brothers, a French portal about Microsoft .NET technologies.

He is currently employed by Innoveo Solutions since 10/2007 as a Senior Solution Architect, certified Scrum Master and Founding Member.

Founder, owner and Managing Partner of Jobping, which provides a unique and efficient platform for connecting Microsoft skilled job seekers with employers using Microsoft technologies.

Laurent was awarded Most Valuable Professional (MVP) by Microsoft from April 2002 to April 2012.

JetBrains Academy Member
Certified ScrumMaster
My status

Twitter

Flickr

www.flickr.com
This is a Flickr badge showing public photos and videos from Laurent Kempé. Make your own badge here.

Month List

Page List

Laurent Kempé | Conversion from Visual Studio .Net 2003 to Visual Studio 2005
Mar
3
2005

Conversion from Visual Studio .Net 2003 to Visual Studio 2005

This evening (hum morning ;) I decided to give a try to the conversion wizard integrated in Visual Studio 2005 that let you import older 1.1 projects.
I choosed to import my whole website: Tech Head Brothers. You might see next the conversion report:

And the Error List report of a build :

I am impressed about the conversion. Ok I have 2 errors and 133 Warnings, but the warnings are all due to deprecated classes or obsolete methods and the two errors are:

  • Error 134 Program '\Projects\Tech Head Brothers Portal\Database\obj\Debug\Database.exe' does not contain a static 'Main' method suitable for an entry point Database
  • Error 135 Program '\Projects\Tech Head Brothers Portal\Docs\obj\Debug\Docs.exe' does not contain a static 'Main' method suitable for an entry point Docs

Next step is to get the DB in SQL Server 2005 and make some tests. But that the task for another day.

Tomorrow I will be at the French DevDays 2005 in Strasbourg, hope to meet you there.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About Laurent

Laurent Kempé

Laurent Kempé is the editor, founder, and primary contributor of Tech Head Brothers, a French portal about Microsoft .NET technologies.

He is currently employed by Innoveo Solutions since 10/2007 as a Senior Solution Architect, certified Scrum Master and Founding Member.

Founder, owner and Managing Partner of Jobping, which provides a unique and efficient platform for connecting Microsoft skilled job seekers with employers using Microsoft technologies.

Laurent was awarded Most Valuable Professional (MVP) by Microsoft from April 2002 to April 2012.

JetBrains Academy Member
Certified ScrumMaster
My status

Twitter

Flickr

www.flickr.com
This is a Flickr badge showing public photos and videos from Laurent Kempé. Make your own badge here.

Month List

Page List