0

I'm using MVC 4 with .NET Framework 4.5.1.

I'm using an external library to create a chart. The html references a dynamically created image,

<img usemap="#MainContent_C1WebChart1_MAP" id="MainContent_C1WebChart1" src="chartimage.aspx?SessionID=FooBar&amp;Delete=T">

But it's looking at /Home/chartimage.aspx?SessionID=FooBar&amp;Delete=T (which returns file not found)

It currently exists under /chartimage.aspx?SessionID=FooBar&amp;Delete=T

What would be the best way to fix this pathing error? I cannot change the src attribute in the img to include a '/' prior to run time it as this is generated by an external library.

Controller: /Controllers/HomeController

View: /Views/Home/Sitemaster and /Views/Home/Default.aspx.

If I make this view the default startup page it works. RouteConfig:

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
        //localhost:9000 Works great! But I don't want this as the default page.
        //localhost:9000/Home/Index Doesn't work :( It's trying to get the resource from /Home/chartimage.aspx...
WCGPR0
  • 751
  • 1
  • 11
  • 24

1 Answers1

1

use this link on how to change the src value of an image.

If you want to use Rewrite URL:

   <rule name="Remove en" stopProcessing="true">
    <match url="^(.*)/Home$" />
    <action type="Rewrite" url="{R:1}" />
</rule>

if your example is www.local.com/home/chartimage.aspx will be rewritten as

www.local.com/chartimage.aspx
ISHIDA
  • 4,700
  • 2
  • 16
  • 30
  • Thanks for the link Ishida! I was thinking of that; would this be good practice? Or would remapping the routes on the server side be a better option – WCGPR0 Jun 05 '17 at 17:17
  • I would say handle it using jquery, instead of handling it through routes. Other way is to write a rewrite rule in your web.config file. – ISHIDA Jun 05 '17 at 17:22
  • Could you also provide an example in your answer of a rewrite rule that redirects /Home/* to /* (except for existing routes defined in RouteConfig)? – WCGPR0 Jun 05 '17 at 17:32
  • 1
    I have updated my answer with a sample rewrite rule which you can use. FYI.. You also need to install `URL Rewrite` in your IIS as well. – ISHIDA Jun 05 '17 at 17:47